Class ActiveRecord::Extensions::RangeExt
In: ar-extensions/lib/ar-extensions/extensions.rb
Parent: Object

ActiveRecord::Extension to translate a ruby Range object into SQL‘s BETWEEN … AND … or NOT BETWEEN … AND … . This works on Ranges of Numbers, Dates, Times, etc.

Examples

 # the following two statements are identical because of how Ranges treat .. and ...
 Model.find :all, :conditions=>{ :id => ( 1 .. 2 ) }
 Model.find :all, :conditions=>{ :id => ( 1 ... 2 ) }

 # the following four statements are identical, this finds NOT BETWEEN matches
 Model.find :all, :conditions=>{ :id_ne => ( 4 .. 6 ) }
 Model.find :all, :conditions=>{ :id_not => ( 4 .. 6 ) }
 Model.find :all, :conditions=>{ :id_not_in => ( 4 ..6 ) }
 Model.find :all, :conditions=>{ :id_not_between => ( 4 .. 6 ) }

 # a little more creative, working with date ranges
 Model.find :all, :conditions=>{ :created_on => (Date.now-30 .. Date.now) }

Methods

process  

Constants

NOT_IN_RGX = /^(.+)_(ne|not|not_in|not_between)$/

Public Class methods

[Validate]