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.
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
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)
github.com/peterhoeg/condition_builder
ConditionBuilder has been tested with the following versions
-
1.8.7
-
2.1.2
-
2.3.2
Copyright © 2009 Peter Hoeg. See LICENSE for details.