Module: ActiveRecord::TimeScope::ClassMethods

Defined in:
lib/active_record/time_scope.rb

Instance Method Summary collapse

Instance Method Details

#create_time_range_scope(verb, from_name, to_name) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/active_record/time_scope.rb', line 30

def create_time_range_scope(verb, from_name, to_name)
  model = self
  from_name = "#{table_name}.#{from_name}"
  to_name = "#{table_name}.#{to_name}"
  model.scope "#{verb}_before", ->(time, opts = {}){ TimeRangeProxy.new(model, from_name, to_name).before(time, opts) }
  scope "#{verb}_after", ->(time, opts = {}){ TimeRangeProxy.new(model, from_name, to_name).after(time, opts) }
  scope "#{verb}_within", ->(from, to, from_opts = {}, to_opts = {}){ TimeRangeProxy.new(model, from_name, to_name).within(from, to, from_opts, to_opts) }
end

#create_time_scope(verb, name) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/active_record/time_scope.rb', line 22

def create_time_scope(verb, name)
  model = self
  name = "#{table_name}.#{name}"
  scope "#{verb}_before", ->(time, opts = {}){ TimeProxy.new(model, name).before(time, opts) }
  scope "#{verb}_after", ->(time, opts = {}){ TimeProxy.new(model, name).after(time, opts) }
  scope "#{verb}_within", ->(from, to, from_opts = {}, to_opts = {}){ TimeProxy.new(model, name).within(from, to, from_opts, to_opts) }
end

#create_time_scopesObject



13
14
15
16
17
18
19
20
# File 'lib/active_record/time_scope.rb', line 13

def create_time_scopes
  return unless table_exists?
  column_names.each do |cn|
    verb = cn.sub TIME_POSTFIX_REGEXP, ''
    next if verb == cn
    create_time_scope verb, cn
  end
end