Skip to content

Commit

Permalink
take less risky path when monkeypatching named_scope; fix that it no …
Browse files Browse the repository at this point in the history
…longer requires ActiveRecord::VERSION
  • Loading branch information
mislav committed Apr 7, 2008
1 parent 5ec1aca commit 674205d
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions lib/will_paginate/named_scope_patch.rb
Expand Up @@ -11,23 +11,12 @@ def with_scope(*args, &block)
ActiveRecord::Associations::HasManyThroughAssociation ].each do |klass|
klass.class_eval do
protected
def method_missing_without_paginate(method, *args)
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
if block_given?
super { |*block_args| yield(*block_args) }
else
super
end
elsif @reflection.klass.scopes.include?(method)
@reflection.klass.scopes[method].call(self, *args)
alias :method_missing_without_scopes :method_missing_without_paginate
def method_missing_without_paginate(method, *args, &block)
if @reflection.klass.scopes.include?(method)
@reflection.klass.scopes[method].call(self, *args, &block)
else
with_scope construct_scope do
if block_given?
@reflection.klass.send(method, *args) { |*block_args| yield(*block_args) }
else
@reflection.klass.send(method, *args)
end
end
method_missing_without_scopes(method, *args, &block)
end
end
end
Expand All @@ -47,4 +36,4 @@ def method_missing(method, *args, &block)
end
end
end
end if ActiveRecord::VERSION::MAJOR < 2
end if ActiveRecord::Base.respond_to? :find_first

0 comments on commit 674205d

Please sign in to comment.