Module: RQuery::ActiveRecord::ClassMethods
- Defined in:
- lib/rquery/active_record/base.rb
Instance Method Summary collapse
Instance Method Details
#sniper_scope(name, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/rquery/active_record/base.rb', line 21 def sniper_scope(name, &block) #rescope self klass = self named_scope name, lambda { |*args| collector = AttributeCollection.new(klass.columns.map {|x| x.name }) block.call(collector, *args) { :conditions => collector.clauses.to_conditions } } end |
#where(*args) {|collector| ... } ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rquery/active_record/base.rb', line 4 def where(*args, &block) collector = AttributeCollection.new(columns.map {|x| x.name }) #Passes a new AttributeCollection object to the block, which will in turn #instantiate a OperationCollector to be used for each expression yield(collector) #record altered conditions and values conditions = collector.clauses.to_conditions #limit the records returned (:first, :all, :last) limit = args.first ? args.first : :all #call find with the conditions and values provided by the block find(limit, :conditions => conditions) end |