Permalink
Browse files

Add hook method conditions_array to change the order in which conditi…

…ons are called in the search object
  • Loading branch information...
1 parent 1d928ae commit b662e3d0e9ad8d9f5ed006467cb4831293aa91aa @binarylogic committed Jan 26, 2010
View
@@ -20,7 +20,7 @@ Install the gem from rubyforge:
sudo gem install searchlogic
-Now just include it in your project and you are ready to go.
+Now just set it as a dependency in your project and you are ready to go.
You can also install this as a plugin:
View
@@ -1,7 +1,7 @@
require "searchlogic/core_ext/proc"
require "searchlogic/core_ext/object"
require "searchlogic/active_record/consistency"
-require "searchlogic/active_record/named_scopes"
+require "searchlogic/active_record/named_scope_tools"
require "searchlogic/named_scopes/conditions"
require "searchlogic/named_scopes/ordering"
require "searchlogic/named_scopes/association_conditions"
@@ -19,7 +19,7 @@ class << self; include Searchlogic::ActiveRecord::Consistency; end
end
end
-ActiveRecord::Base.extend(Searchlogic::ActiveRecord::NamedScopes)
+ActiveRecord::Base.extend(Searchlogic::ActiveRecord::NamedScopeTools)
ActiveRecord::Base.extend(Searchlogic::NamedScopes::Conditions)
ActiveRecord::Base.extend(Searchlogic::NamedScopes::AssociationConditions)
ActiveRecord::Base.extend(Searchlogic::NamedScopes::AssociationOrdering)
@@ -1,7 +1,7 @@
module Searchlogic
module ActiveRecord
# Adds methods that give extra information about a classes named scopes.
- module NamedScopes
+ module NamedScopeTools
# Retrieves the options passed when creating the respective named scope. Ex:
#
# named_scope :whatever, :conditions => {:column => value}
@@ -100,7 +100,7 @@ def method_missing(name, *args, &block)
self
end
else
- scope = conditions.inject(klass.scoped(current_scope) || {}) do |scope, condition|
+ scope = conditions_array.inject(klass.scoped(current_scope) || {}) do |scope, condition|
scope_name, value = condition
scope_name = normalize_scope_name(scope_name)
klass.send(scope_name, value) if !klass.respond_to?(scope_name)
@@ -122,6 +122,11 @@ def method_missing(name, *args, &block)
end
end
+ # This is here as a hook to allow people to modify the order in which the conditions are called, for whatever reason.
+ def conditions_array
+ conditions.to_a
+ end
+
def normalize_scope_name(scope_name)
case
when klass.scopes.key?(scope_name.to_sym) then scope_name.to_sym

0 comments on commit b662e3d

Please sign in to comment.