Module: Groupdate::Scopes

Defined in:
lib/groupdate/scopes.rb

Instance Method Summary collapse

Instance Method Details

#group_by_period(period, field, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/groupdate/scopes.rb', line 14

def group_by_period(period, field, options = {})
  # to_sym is unsafe on user input, so convert to strings
  permitted_periods = ((options[:permit] || Groupdate::PERIODS).map(&:to_sym) & Groupdate::PERIODS).map(&:to_s)
  if permitted_periods.include?(period.to_s)
    send("group_by_#{period}", field, options)
  else
    raise ArgumentError, "Unpermitted period"
  end
end