Skip to content

speartail/condition_builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

condition_builder

ConditionBuilder generates conditions and criteria for use in ActiveRecord .find statements to avoid manually having to construct a string of conditions and the releveant hash with values.

It does not support fancy dependencies between the statements as it would make the syntax so complicated that people might as well generate the condition string and hash themselves.

Installation

Please install it from rubyforge (github is not generating this gem as it insists on prefixing the gem name with the github username).

sudo gem install condition_builder

Usage

cb = ConditionBuilder.new
# add a condition "user_id < 4" in descending order
cb.add('user_id <', 4, :desc)
# add a condition "user_location like '%abc'" in ascending order
cb.add('user_location like', '%abc', :asc)
# add a condition "department_id = 18"
cb.add('department_id = ', 18)

User.find(:all, :conditions => cb.conditions, :order => cb.order, cb.criteria)

Website

github.com/peterhoeg/condition_builder

Requirements

ConditionBuilder has been tested with the following versions

Ruby

  • 1.8.7

Rails

  • 2.1.2

  • 2.3.2

Copyright © 2009 Peter Hoeg. See LICENSE for details.

About

ConditionBuilder for generating parameters to ActiveRecord.find

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages