0
@@ -17,12 +17,37 @@ module Squirrel
0
+ def scoped_with_squirrel *args, &blk
0
+ query = Query.new(self, &blk)
0
+ self.scoped(query.to_find_parameters)
0
+ scoped_without_squirrel(*args)
0
- return if base.instance_methods.include? 'find_without_squirrel'
0
- alias_method :find_without_squirrel, :find
0
- alias_method :find, :find_with_squirrel
0
+ if ! base.instance_methods.include?('find_without_squirrel') &&
0
+ base.instance_methods.include?('find')
0
+ alias_method :find_without_squirrel, :find
0
+ alias_method :find, :find_with_squirrel
0
+ if ! base.instance_methods.include?('scoped_without_squirrel') &&
0
+ base.instance_methods.include?('scoped')
0
+ alias_method :scoped_without_squirrel, :scoped
0
+ alias_method :scoped, :scoped_with_squirrel
0
+ def scoped *args, &blk
0
+ args = blk ? [Query.new(self, &blk).to_find_parameters] : args
0
+ scopes[:scoped].call(self, *args)
0
@@ -64,20 +89,25 @@ module Squirrel
0
pagination = opts.delete(:paginate) || {}
0
model.send(:with_scope, :find => opts) do
0
@conditions.paginate(pagination) unless pagination.empty?
0
- find_parameters = { :conditions => to_find_conditions,
0
- :include => to_find_include,
0
- :order => to_find_order,
0
- :limit => to_find_limit,
0
- :offset => to_find_offset }
0
- results = model.find args[0], find_parameters
0
+ results = model.find args[0], to_find_parameters
0
if @conditions.paginate?
0
- paginate_result_set results,
find_parameters
0
+ paginate_result_set results,
to_find_parameters
0
+ def to_find_parameters
0
+ find_parameters[:conditions] = to_find_conditions unless to_find_conditions.blank?
0
+ find_parameters[:include ] = to_find_include unless to_find_include.blank?
0
+ find_parameters[:order ] = to_find_order unless to_find_order.blank?
0
+ find_parameters[:limit ] = to_find_limit unless to_find_limit.blank?
0
+ find_parameters[:offset ] = to_find_offset unless to_find_offset.blank?
0
# Delegates the to_find_conditions call to the root ConditionGroup
0
@conditions.to_find_conditions
Comments
No one has commented yet.