Module: Timeframeable::Controller::ClassMethods

Defined in:
lib/timeframeable/controller.rb

Instance Method Summary collapse

Instance Method Details

#timeframeable(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/timeframeable/controller.rb', line 6

def timeframeable(options={})
  options = options.dup
  options[:start_key] ||= :start
  options[:end_key]   ||= :end
  options[:variable]  ||= :timeframe
  options[:defaults]  ||= []
  options[:defaults] = options[:defaults].map do |x|
    if x.is_a? Symbol
      if x == :now
        DateTime.now.utc
      else
        DateTime.now.send(x).utc
      end
    else
      x && x.to_datetime.utc
    end
  end

  before_filter do
    set_timeframe options
  end
end