Module: RailsPulse::Extensions::ActiveRecord::ResultTransformer
- Included in:
- DateResultTransformer, HourResultTransformer
- Defined in:
- lib/rails_pulse/extensions/active_record.rb
Overview
Shared base for transforming aggregation result hash keys. Include this module and implement #parse_key to specialize.
Instance Method Summary collapse
- #average(*args) ⇒ Object
- #count(*args) ⇒ Object
- #maximum(*args) ⇒ Object
- #minimum(*args) ⇒ Object
- #pluck(*args) ⇒ Object
- #sum(*args) ⇒ Object
Instance Method Details
#average(*args) ⇒ Object
74 75 76 |
# File 'lib/rails_pulse/extensions/active_record.rb', line 74 def average(*args) super.transform_keys { |k| parse_key(k) } end |
#count(*args) ⇒ Object
68 69 70 71 72 |
# File 'lib/rails_pulse/extensions/active_record.rb', line 68 def count(*args) result = super # count can return an integer or a hash depending on whether group is used result.is_a?(Hash) ? result.transform_keys { |k| parse_key(k) } : result end |
#maximum(*args) ⇒ Object
78 79 80 |
# File 'lib/rails_pulse/extensions/active_record.rb', line 78 def maximum(*args) super.transform_keys { |k| parse_key(k) } end |
#minimum(*args) ⇒ Object
82 83 84 |
# File 'lib/rails_pulse/extensions/active_record.rb', line 82 def minimum(*args) super.transform_keys { |k| parse_key(k) } end |
#pluck(*args) ⇒ Object
86 87 88 89 |
# File 'lib/rails_pulse/extensions/active_record.rb', line 86 def pluck(*args) result = super result.is_a?(Hash) ? result.transform_keys { |k| parse_key(k) } : result end |
#sum(*args) ⇒ Object
64 65 66 |
# File 'lib/rails_pulse/extensions/active_record.rb', line 64 def sum(*args) super.transform_keys { |k| parse_key(k) } end |