Sha256: 98a54676aec25f1fd9dc6f6440bc8c70820a7d65a274b27a2b0d428cc7288ae1

Contents?: true

Size: 1.97 KB

Versions: 44

Compression:

Stored size: 1.97 KB

Contents

require 'active_support'

# = You *will* paginate!
#
# First read about WillPaginate::Finder::ClassMethods, then see
# WillPaginate::ViewHelpers. The magical array you're handling in-between is
# WillPaginate::Collection.
#
# Happy paginating!
module WillPaginate
  class << self
    # shortcut for <tt>enable_actionpack; enable_activerecord</tt>
    def enable
      enable_actionpack
      enable_activerecord
    end
    
    # mixes in WillPaginate::ViewHelpers in ActionView::Base
    def enable_actionpack
      return if ActionView::Base.instance_methods.include? 'will_paginate'
      require 'will_paginate/view_helpers'
      ActionView::Base.class_eval { include ViewHelpers }
    end
    
    # mixes in WillPaginate::Finder in ActiveRecord::Base and classes that deal
    # with associations
    def enable_activerecord
      return if ActiveRecord::Base.respond_to? :paginate
      require 'will_paginate/finder'
      ActiveRecord::Base.class_eval { include Finder }

      associations = ActiveRecord::Associations
      collection = associations::AssociationCollection
      
      # to support paginating finders on associations, we have to mix in the
      # method_missing magic from WillPaginate::Finder::ClassMethods to AssociationProxy
      # subclasses, but in a different way for Rails 1.2.x and 2.0
      (collection.instance_methods.include?(:create!) ?
        collection : collection.subclasses.map(&:constantize)
      ).push(associations::HasManyThroughAssociation).each do |klass|
        klass.class_eval do
          include Finder::ClassMethods
          alias_method_chain :method_missing, :paginate
        end
      end
    end
  end

  module Deprecation #:nodoc:
    extend ActiveSupport::Deprecation

    def self.warn(message, callstack = caller)
      message = 'WillPaginate: ' + message.strip.gsub(/ {3,}/, ' ')
      behavior.call(message, callstack) if behavior && !silenced?
    end

    def self.silenced?
      ActiveSupport::Deprecation.silenced?
    end
  end
end

Version data entries

44 entries across 44 versions & 2 rubygems

Version Path
backlog-0.37.2 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.37.1 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.36.2 vendor/plugins/will_paginate/lib/will_paginate.rb
amrita2-2.0.1 sample/depot/vendor/plugins/will_paginate/lib/will_paginate.rb
amrita2-2.0.2 sample/depot/vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.17.0 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.17.2 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.17.1 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.17.3 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.17.4 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.17.5 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.17.6 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.18.0 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.19.0 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.20.0 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.20.1 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.21.0 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.21.2 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.21.1 vendor/plugins/will_paginate/lib/will_paginate.rb
backlog-0.21.3 vendor/plugins/will_paginate/lib/will_paginate.rb