7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/timescopes/rails/active_record_extension.rb', line 7
def timescoped!(opts={})
default_scopes = [:minutely, :hourly, :daily, :weekly, :monthly]
field = opts[:field] || "created_at"
scopes = if opts[:only]
Array(opts[:only]).map(&:to_sym) & default_scopes
else
default_scopes
end
scopes.each do |scope|
eval %%
def #{scope}(start=nil)
start, finish = TimeScopes.#{scope}(start)
where('#{field} >= ? AND #{field} < ?', start.utc, finish.utc)
end
%
end
end
|