Class: RailsPerformance::Collection
- Inherits:
-
Object
- Object
- RailsPerformance::Collection
- Defined in:
- lib/rails_performance/collection.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #add(record) ⇒ Object
- #group_by(type) ⇒ Object
-
#initialize ⇒ Collection
constructor
A new instance of Collection.
- #values ⇒ Object
Constructor Details
#initialize ⇒ Collection
5 6 7 |
# File 'lib/rails_performance/collection.rb', line 5 def initialize @data = [] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/rails_performance/collection.rb', line 3 def data @data end |
Instance Method Details
#add(record) ⇒ Object
9 10 11 |
# File 'lib/rails_performance/collection.rb', line 9 def add(record) @data << record end |
#group_by(type) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/rails_performance/collection.rb', line 13 def group_by(type) @data = case type when :controller_action, :controller_action_format, :datetime, :path @data.group_by(&type) else [] end self end |
#values ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rails_performance/collection.rb', line 23 def values return [] if @data.empty? result = {} @data.each do |key, records| result[key] ||= [] records.each do |record| result[key] << record.value end end result end |