Class: ActiveRecord::TimeScope::TimeProxy

Inherits:
ScopeProxy
  • Object
show all
Defined in:
lib/active_record/time_scope/time_proxy.rb

Instance Method Summary collapse

Methods inherited from ScopeProxy

new

Constructor Details

#initialize(model, column_name) ⇒ TimeProxy

Returns a new instance of TimeProxy.



6
7
8
9
# File 'lib/active_record/time_scope/time_proxy.rb', line 6

def initialize(model, column_name)
  @model = model
  @column_name = column_name
end

Instance Method Details

#after(time, opts = {}) ⇒ Object



16
17
18
19
# File 'lib/active_record/time_scope/time_proxy.rb', line 16

def after(time, opts = {})
  operator = opts[:include_equal].to_s != '' ? '<=' : '<'
  @model.where("? #{operator} #{@column_name}", time)
end

#before(time, opts = {}) ⇒ Object



11
12
13
14
# File 'lib/active_record/time_scope/time_proxy.rb', line 11

def before(time, opts = {})
  operator = opts[:include_equal].to_s != '' ? '<=' : '<'
  @model.where("#{@column_name} #{operator} ?", time)
end

#within(from, to, from_opts = {}, to_opts = {}) ⇒ Object



21
22
23
24
25
# File 'lib/active_record/time_scope/time_proxy.rb', line 21

def within(from, to, from_opts = {}, to_opts = {})
  from_operator = from_opts[:include_equal].to_s != '' ? '<=' : '<'
  to_operator = to_opts[:include_equal].to_s != '' ? '<=' : '<'
  @model.where("? #{from_operator} #{@column_name} AND #{@column_name} #{to_operator} ?", from, to)
end