Module: MeterBox::Aggregation

Defined in:
lib/meter_box/aggregation.rb

Class Method Summary collapse

Class Method Details

.apply(scope, aggregation) ⇒ Object



6
7
8
9
10
# File 'lib/meter_box/aggregation.rb', line 6

def apply(scope, aggregation)
  return scope.order(recorded_at: :desc, created_at: :desc).pick(:value) if aggregation == :latest

  dispatch(scope, aggregation)
end

.apply_grouped(scope, group_sql, aggregation) ⇒ Object



12
13
14
15
16
# File 'lib/meter_box/aggregation.rb', line 12

def apply_grouped(scope, group_sql, aggregation)
  return latest_per_group(scope, group_sql) if aggregation == :latest

  dispatch(scope.group(Arel.sql(group_sql)), aggregation)
end