Sha256: a6db803be97398858a4208e810da274348eaec04cf2ee533a8668cc782875eec
Contents?: true
Size: 846 Bytes
Versions: 1
Compression:
Stored size: 846 Bytes
Contents
module TimeScopes module Rails module ActiveRecordExtension extend ActiveSupport::Concern module ClassMethods def timescoped!(opts={}) default_scopes = [: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 end end end end ActiveRecord::Base.send(:include, TimeScopes::Rails::ActiveRecordExtension)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
timescopes-0.1.1 | lib/timescopes/rails/active_record_extension.rb |