Class: FactoryBotProfile::AggregateStats

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

Instance Method Summary collapse

Constructor Details

#initializeAggregateStats

Returns a new instance of AggregateStats.



5
6
7
# File 'lib/factory_bot_profile/aggregate_stats.rb', line 5

def initialize
  @by_factory = stats_hash
end

Instance Method Details

#collect(frame) ⇒ Object



9
10
11
# File 'lib/factory_bot_profile/aggregate_stats.rb', line 9

def collect(frame)
  @by_factory[frame.name].increment(frame)
end

#each_factoryObject



50
51
52
# File 'lib/factory_bot_profile/aggregate_stats.rb', line 50

def each_factory(...)
  @by_factory.each(...)
end

#highest_average_time(n = 1) ⇒ Object



29
30
31
# File 'lib/factory_bot_profile/aggregate_stats.rb', line 29

def highest_average_time(n = 1)
  take_factory_values_by(:average_time, n)
end

#highest_count(n = 1) ⇒ Object



17
18
19
# File 'lib/factory_bot_profile/aggregate_stats.rb', line 17

def highest_count(n = 1)
  take_factory_values_by(:count, n)
end

#highest_self_time(n = 1) ⇒ Object



25
26
27
# File 'lib/factory_bot_profile/aggregate_stats.rb', line 25

def highest_self_time(n = 1)
  take_factory_values_by(:total_self_time, n)
end

#highest_total_time(n = 1) ⇒ Object



21
22
23
# File 'lib/factory_bot_profile/aggregate_stats.rb', line 21

def highest_total_time(n = 1)
  take_factory_values_by(:total_time, n)
end

#marshal_dumpObject



33
34
35
36
37
# File 'lib/factory_bot_profile/aggregate_stats.rb', line 33

def marshal_dump
  # Cannot dump hash with a default proc, so make a copy with no default
  # Need to disable standard because to_h is not the same thing in this case
  Hash[@by_factory] # rubocop:disable Style/HashConversion
end

#marshal_load(by_factory) ⇒ Object



39
40
41
# File 'lib/factory_bot_profile/aggregate_stats.rb', line 39

def marshal_load(by_factory)
  @by_factory = stats_hash.merge!(by_factory)
end

#merge!(other) ⇒ Object



43
44
45
46
47
48
# File 'lib/factory_bot_profile/aggregate_stats.rb', line 43

def merge!(other)
  other.each_factory do |name, stat|
    @by_factory[name].merge!(stat)
  end
  self
end

#total_timeObject



13
14
15
# File 'lib/factory_bot_profile/aggregate_stats.rb', line 13

def total_time
  @by_factory.values.map(&:total_self_time).sum
end