-
Notifications
You must be signed in to change notification settings - Fork 20
Scopes
Vlad edited this page Feb 11, 2015
·
1 revision
Influxer metrics support scopes of two types: default and named (just like ActiveRecord).
class VisitsMetrics < Influxer::Metrics
default_scope, -> { time(:hour) }
scope :by_user, ->(id) { where(user: id) if id.present? }
end
# default scope
VisitsMetrics.all #=> select * from visits group by time(1h)
# named scope
VisitsMetrics.by_user(1) #=> select * from visits group by time(1h) where user_id=1
# unscoped
VisitsMetrics.unscoped.by_user(1).time(:day) #=> select * from visits group by time(1d) where user_id=1