Class: FactoryBotProfile::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_bot_profile/frame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_timeObject

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

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/factory_bot_profile/frame.rb', line 3

def name
  @name
end

#startObject

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

#durationObject



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_timeObject



27
28
29
# File 'lib/factory_bot_profile/frame.rb', line 27

def self_time
  duration - total_child_time
end

#total_child_timeObject



31
32
33
# File 'lib/factory_bot_profile/frame.rb', line 31

def total_child_time
  @child_time.values.sum
end