Class: ActiveRecord::TimeScope::TimeRangeProxy

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

Instance Method Summary collapse

Methods inherited from ScopeProxy

new

Constructor Details

#initialize(model, column_name1, column_name2) ⇒ TimeRangeProxy

Returns a new instance of TimeRangeProxy.



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

def initialize(model, column_name1, column_name2)
  @model = model
  @column_name1 = column_name1
  @column_name2 = column_name2
end

Instance Method Details

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



17
18
19
20
# File 'lib/active_record/time_scope/time_range_proxy.rb', line 17

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

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



12
13
14
15
# File 'lib/active_record/time_scope/time_range_proxy.rb', line 12

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

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



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

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_name1} AND #{@column_name2} #{to_operator} ?", from, to)
end