Class: FactoryBotProfile::AggregateStats
- Inherits:
-
Object
- Object
- FactoryBotProfile::AggregateStats
- Defined in:
- lib/factory_bot_profile/aggregate_stats.rb
Instance Method Summary collapse
- #collect(frame) ⇒ Object
- #each_factory ⇒ Object
- #highest_average_time(n = 1) ⇒ Object
- #highest_count(n = 1) ⇒ Object
- #highest_self_time(n = 1) ⇒ Object
- #highest_total_time(n = 1) ⇒ Object
-
#initialize ⇒ AggregateStats
constructor
A new instance of AggregateStats.
- #marshal_dump ⇒ Object
- #marshal_load(by_factory) ⇒ Object
- #merge!(other) ⇒ Object
- #total_time ⇒ Object
Constructor Details
#initialize ⇒ AggregateStats
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_factory ⇒ Object
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_dump ⇒ Object
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_time ⇒ Object
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 |