Class: Operation
- Inherits:
-
Object
- Object
- Operation
- Defined in:
- lib/yuslow/operation.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
- #complete ⇒ Object
- #elapsed ⇒ Object
- #fork(object:, method:) ⇒ Object
- #identifier ⇒ Object
-
#initialize(object:, method:, parent: nil, started_at: Time.now, completed_at: nil, children: []) ⇒ Operation
constructor
A new instance of Operation.
Constructor Details
#initialize(object:, method:, parent: nil, started_at: Time.now, completed_at: nil, children: []) ⇒ Operation
Returns a new instance of Operation.
10 11 12 13 14 15 16 17 |
# File 'lib/yuslow/operation.rb', line 10 def initialize(object:, method:, parent: nil, started_at: Time.now, completed_at: nil, children: []) @object = object @method = method @started_at = started_at @completed_at = completed_at @parent = parent @children = children end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
2 3 4 |
# File 'lib/yuslow/operation.rb', line 2 def children @children end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
2 3 4 |
# File 'lib/yuslow/operation.rb', line 2 def parent @parent end |
Class Method Details
.start(object, method) ⇒ Object
5 6 7 |
# File 'lib/yuslow/operation.rb', line 5 def start(object, method) new(object, method) end |
Instance Method Details
#complete ⇒ Object
30 31 32 33 34 |
# File 'lib/yuslow/operation.rb', line 30 def complete raise 'This operation is already completed' if @completed_at @completed_at = Time.now end |
#elapsed ⇒ Object
36 37 38 |
# File 'lib/yuslow/operation.rb', line 36 def elapsed ((@completed_at - @started_at) * 1000).round if @completed_at end |
#fork(object:, method:) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/yuslow/operation.rb', line 19 def fork(object:, method:) operation = self.class.new object: object, method: method, parent: self @children << operation operation end |
#identifier ⇒ Object
26 27 28 |
# File 'lib/yuslow/operation.rb', line 26 def identifier "#{@object}##{@method}" end |