Class: FactoryBotProfile::Frame
- Inherits:
-
Object
- Object
- FactoryBotProfile::Frame
- Defined in:
- lib/factory_bot_profile/frame.rb
Instance Attribute Summary collapse
-
#child_time ⇒ Object
Returns the value of attribute child_time.
-
#name ⇒ Object
Returns the value of attribute name.
-
#start ⇒ Object
Returns the value of attribute start.
Instance Method Summary collapse
- #duration ⇒ Object
- #finish! ⇒ Object
-
#initialize(name) ⇒ Frame
constructor
A new instance of Frame.
- #observe_child(frame) ⇒ Object
- #self_time ⇒ Object
- #total_child_time ⇒ Object
Constructor Details
#initialize(name) ⇒ Frame
Returns a new instance of Frame.
5 6 7 8 9 |
# File 'lib/factory_bot_profile/frame.rb', line 5 def initialize(name) @name = name @start = Time.now @child_time = Hash.new { 0 } end |
Instance Attribute Details
#child_time ⇒ Object
Returns the value of attribute child_time.
3 4 5 |
# File 'lib/factory_bot_profile/frame.rb', line 3 def child_time @child_time end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/factory_bot_profile/frame.rb', line 3 def name @name end |
#start ⇒ Object
Returns the value of attribute start.
3 4 5 |
# File 'lib/factory_bot_profile/frame.rb', line 3 def start @start end |
Instance Method Details
#duration ⇒ Object
18 19 20 21 |
# File 'lib/factory_bot_profile/frame.rb', line 18 def duration raise "self time called before frame was stopped" unless @duration @duration end |
#finish! ⇒ Object
23 24 25 |
# File 'lib/factory_bot_profile/frame.rb', line 23 def finish! @duration = Time.now - @start end |
#observe_child(frame) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/factory_bot_profile/frame.rb', line 11 def observe_child(frame) @child_time[frame.name] += frame.self_time frame.child_time.each do |factory_name, time| @child_time[factory_name] += time end end |
#self_time ⇒ Object
27 28 29 |
# File 'lib/factory_bot_profile/frame.rb', line 27 def self_time duration - total_child_time end |
#total_child_time ⇒ Object
31 32 33 |
# File 'lib/factory_bot_profile/frame.rb', line 31 def total_child_time @child_time.values.sum end |