Class: ActiveRecord::TimeScope::TimeRangeProxy
- Inherits:
-
ScopeProxy
- Object
- ScopeProxy
- ActiveRecord::TimeScope::TimeRangeProxy
- Defined in:
- lib/active_record/time_scope/time_range_proxy.rb
Instance Method Summary collapse
- #after(time, opts = {}) ⇒ Object
- #before(time, opts = {}) ⇒ Object
-
#initialize(model, column_name1, column_name2) ⇒ TimeRangeProxy
constructor
A new instance of TimeRangeProxy.
- #within(from, to, from_opts = {}, to_opts = {}) ⇒ Object
Methods inherited from ScopeProxy
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 |