Sha256: 0c8295d2187c3bf19f0bd9bba35775d81a87f4a6846471e0182efc52e53559b7
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
require_relative 'scope_proxy' module ActiveRecord module TimeScope class TimeRangeProxy < ScopeProxy def initialize(model, column_name1, column_name2) @model = model @column_name1 = column_name1 @column_name2 = column_name2 end def before(time, opts = {}) operator = opts[:include_equal].to_s != '' ? '=<' : '<' @model.where("#{@column_name1} #{operator} ? AND #{@column_name2} #{operator} ?", time, time) end def after(time, opts = {}) operator = opts[:include_equal].to_s != '' ? '=<' : '<' @model.where("? #{operator} #{@column_name1} AND ? #{operator} #{@column_name2}", time, time) end 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activerecord-time-scope-0.0.1 | lib/active_record/time_scope/time_range_proxy.rb |