From 6b037511b4a9541c892fdf559ac4bd81856d0dac Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 30 Oct 2013 19:15:01 -0300 Subject: [PATCH] named_scope_monkey_patch: move to solr plugin --- plugins/solr/vendor/plugins/named_scope_with_applied_names/init.rb | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ vendor/plugins/monkey_patches/named_scope_with_applied_names/init.rb | 57 --------------------------------------------------------- 2 files changed, 57 insertions(+), 57 deletions(-) create mode 100644 plugins/solr/vendor/plugins/named_scope_with_applied_names/init.rb delete mode 100644 vendor/plugins/monkey_patches/named_scope_with_applied_names/init.rb diff --git a/plugins/solr/vendor/plugins/named_scope_with_applied_names/init.rb b/plugins/solr/vendor/plugins/named_scope_with_applied_names/init.rb new file mode 100644 index 0000000..7dac14a --- /dev/null +++ b/plugins/solr/vendor/plugins/named_scope_with_applied_names/init.rb @@ -0,0 +1,57 @@ +require_dependency 'active_record/named_scope' + +if Rails::VERSION::STRING < "2.3.99" + + module ::ActiveRecord + + module NamedScope + + module ClassMethods + + def named_scope_with_applied_names name, options = {}, &block + named_scope_without_applied_names name, options, &block + + name = name.to_sym + scopes[name] = lambda do |parent_scope, *args| + scope = Scope.new(parent_scope, case options + when Hash + options + when Proc + if self.model_name != parent_scope.model_name + options.bind(parent_scope).call(*args) + else + options.call(*args) + end + end, &block) + scope.scope_name = name + scope + end + end + alias_method_chain :named_scope, :applied_names + end + + class Scope + attr_accessor :scope_name, :scopes_applied + + def initialize_with_applied_names proxy_scope, options, &block + initialize_without_applied_names proxy_scope, options, &block + self.scopes_applied ||= [] + self.scopes_applied += proxy_scope.send :scopes_applied if Scope === proxy_scope + + # unrelated bugfix: use if instead of unless + if (Scope === proxy_scope || ActiveRecord::Associations::AssociationCollection === proxy_scope) + @current_scoped_methods_when_defined = proxy_scope.send(:current_scoped_methods) + end + end + alias_method_chain :initialize, :applied_names + + def scope_name= name + @scope_name = name + self.scopes_applied << @scope_name + end + + end + + end + end +end diff --git a/vendor/plugins/monkey_patches/named_scope_with_applied_names/init.rb b/vendor/plugins/monkey_patches/named_scope_with_applied_names/init.rb deleted file mode 100644 index 7dac14a..0000000 --- a/vendor/plugins/monkey_patches/named_scope_with_applied_names/init.rb +++ /dev/null @@ -1,57 +0,0 @@ -require_dependency 'active_record/named_scope' - -if Rails::VERSION::STRING < "2.3.99" - - module ::ActiveRecord - - module NamedScope - - module ClassMethods - - def named_scope_with_applied_names name, options = {}, &block - named_scope_without_applied_names name, options, &block - - name = name.to_sym - scopes[name] = lambda do |parent_scope, *args| - scope = Scope.new(parent_scope, case options - when Hash - options - when Proc - if self.model_name != parent_scope.model_name - options.bind(parent_scope).call(*args) - else - options.call(*args) - end - end, &block) - scope.scope_name = name - scope - end - end - alias_method_chain :named_scope, :applied_names - end - - class Scope - attr_accessor :scope_name, :scopes_applied - - def initialize_with_applied_names proxy_scope, options, &block - initialize_without_applied_names proxy_scope, options, &block - self.scopes_applied ||= [] - self.scopes_applied += proxy_scope.send :scopes_applied if Scope === proxy_scope - - # unrelated bugfix: use if instead of unless - if (Scope === proxy_scope || ActiveRecord::Associations::AssociationCollection === proxy_scope) - @current_scoped_methods_when_defined = proxy_scope.send(:current_scoped_methods) - end - end - alias_method_chain :initialize, :applied_names - - def scope_name= name - @scope_name = name - self.scopes_applied << @scope_name - end - - end - - end - end -end -- libgit2 0.21.2