0
@@ -33,68 +33,26 @@ module WillPaginate
0
require 'will_paginate/finder'
0
ActiveRecord::Base.class_eval { include Finder }
0
- if patch_named_scope = !defined?(ActiveRecord::NamedScope)
0
- # bring in a Rails 2.1 feature
0
- require 'will_paginate/named_scope'
0
- ActiveRecord::Base.class_eval do
0
- include WillPaginate::NamedScope
0
- ActiveRecord::Associations::AssociationProxy.class_eval do
0
- def with_scope(*args, &block)
0
- @reflection.klass.send :with_scope, *args, &block
0
# support pagination on associations
0
[ ActiveRecord::Associations::AssociationCollection,
0
ActiveRecord::Associations::HasManyThroughAssociation ].each do |klass|
0
- def method_missing(method, *args)
0
- if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
0
- super { |*block_args| yield(*block_args) }
0
- elsif @reflection.klass.scopes.include?(method)
0
- @reflection.klass.scopes[method].call(self, *args)
0
- with_scope construct_scope do
0
- @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) }
0
- @reflection.klass.send(method, *args)
0
- end if patch_named_scope
0
include Finder::ClassMethods
0
alias_method_chain :method_missing, :paginate
0
- ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do
0
- def method_missing(method, *args, &block)
0
- if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method))
0
- elsif @reflection.klass.scopes.include?(method)
0
- @reflection.klass.scopes[method].call(self, *args)
0
- @reflection.klass.with_scope(:find => { :conditions => @finder_sql, :joins => @join_sql, :readonly => false }) do
0
- @reflection.klass.send(method, *args, &block)
0
- end if ActiveRecord::VERSION::MAJOR < 2 and patch_named_scope
0
+ # Enable named_scope, a feature of Rails 2.1, even if you have older Rails
0
+ # (tested on Rails 2.0.2 and 1.2.6).
0
+ def enable_named_scope(patch = true)
0
+ return if defined? ActiveRecord::NamedScope
0
+ require 'will_paginate/named_scope'
0
+ require 'will_paginate/named_scope_patch' if patch
0
+ ActiveRecord::Base.class_eval do
0
+ include WillPaginate::NamedScope
Comments
No one has commented yet.