Where Builder for ActiveRecord plugin

Plugin details

An easier way to create where clauses.

Websitehttp://blog.invisible.ch/2006/01/02/where-plugin/ Repositoryhttp://invisible.ch/svn/projects/plugins/where Author Ezra Zygmuntovic Tags where, condition LicenseRuby's (MIT)

Documentation

Install the plugin:
ruby script/plugin install http://invisible.ch/svn/projects/plugins/where

Uses a block to initialize the condition:

c = InVisible::Cond.new do
   month '<=', 11
   year '=', 2005
   name 'LIKE', 'ruby%'
 end
c.where -> ["month <= ? and year = ? and name LIKE ?", 11, 2005, "ruby%"]


Lets say that you have this hash in your +params+ :

params = { :person => {:name => "dave" :city => "Yakima"}}
c = InVisible::Cond.new do
   person '=', params[:person][:name]
   city   '=', params[:person][:city]
end
MyModel.find(:all, :conditions => c.where)


or simpler:

MyModel.find_with_conditions( :all ) do
   person params[:person][:name]
   city   params[:person][:city]
end


to include direct SQL, use like this:

c = InVisible::Cond.new do
  sql "hosts.id = logs.host_id and hosts.name", 'like', "123.23.45.67"
end


if a value needs to by typed (f.e. in Postgres: "ip < inet ?"), use a form of:

c = InVisible::Cond.new do
   ip '= inet', '123.34.56.78/24'
end


to expand an existing condition, use the << method

c << ['age', '>', 30]

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, about 1 year ago