Permalink
Browse files

mix in Active Record/Action View directly on `require`

Get rid of extra steps, they were a bad idea
  • Loading branch information...
1 parent 3a3e07c commit 4d260bc7afa61fad89924cb25bd04be722470541 @mislav mislav committed Aug 5, 2011
View
@@ -4,15 +4,15 @@
# the initializer defined by the Railtie won't ever run when loaded as plugin.
if defined? ActiveRecord::Base
- WillPaginate::Railtie.setup_activerecord
+ require 'will_paginate/active_record'
end
if defined? ActionController::Base
WillPaginate::Railtie.setup_actioncontroller
end
if defined? ActionView::Base
- WillPaginate::Railtie.setup_actionview
+ require 'will_paginate/view_helpers/action_view'
end
WillPaginate::Railtie.add_locale_path config
@@ -15,23 +15,6 @@ module WillPaginate
# @posts = Post.paginate :all, :page => params[:page], :order => 'created_at DESC'
#
module ActiveRecord
- # In Rails, this is automatically called to mix-in pagination functionality to ActiveRecord.
- def self.setup
- ::ActiveRecord::Base.extend PerPage
- ::ActiveRecord::Base.extend ActiveRecord::Pagination
- ::ActiveRecord::Base.extend ActiveRecord::BaseMethods
-
- klasses = [::ActiveRecord::Relation]
- if defined? ::ActiveRecord::Associations::CollectionProxy
- klasses << ::ActiveRecord::Associations::CollectionProxy
- else
- klasses << ::ActiveRecord::Associations::AssociationCollection
- end
-
- # support pagination on associations and scopes
- klasses.each { |klass| klass.send(:include, ActiveRecord::Pagination) }
- end
-
# makes a Relation look like WillPaginate::Collection
module RelationMethods
attr_accessor :current_page
@@ -192,5 +175,20 @@ def paginate_by_sql(sql, options)
end
end
end
+
+ # mix everything into Active Record
+ ::ActiveRecord::Base.extend PerPage
+ ::ActiveRecord::Base.extend Pagination
+ ::ActiveRecord::Base.extend BaseMethods
+
+ klasses = [::ActiveRecord::Relation]
+ if defined? ::ActiveRecord::Associations::CollectionProxy
+ klasses << ::ActiveRecord::Associations::CollectionProxy
+ else
+ klasses << ::ActiveRecord::Associations::AssociationCollection
+ end
+
+ # support pagination on associations and scopes
+ klasses.each { |klass| klass.send(:include, Pagination) }
end
end
@@ -5,34 +5,24 @@ module WillPaginate
class Railtie < Rails::Railtie
initializer "will_paginate" do |app|
ActiveSupport.on_load :active_record do
- WillPaginate::Railtie.setup_activerecord
+ require 'will_paginate/active_record'
end
ActiveSupport.on_load :action_controller do
WillPaginate::Railtie.setup_actioncontroller
end
ActiveSupport.on_load :action_view do
- WillPaginate::Railtie.setup_actionview
+ require 'will_paginate/view_helpers/action_view'
end
self.class.add_locale_path config
end
- def self.setup_activerecord
- require 'will_paginate/active_record'
- WillPaginate::ActiveRecord.setup
- end
-
def self.setup_actioncontroller
ActionDispatch::ShowExceptions.rescue_responses['WillPaginate::InvalidPage'] = :not_found
end
- def self.setup_actionview
- require 'will_paginate/view_helpers/action_view'
- ::ActionView::Base.send :include, WillPaginate::ActionView
- end
-
def self.add_locale_path(config)
locale_path = File.expand_path('../locale', __FILE__)
config.i18n.railties_load_path.concat Dir["#{locale_path}/*.{rb,yml}"]
@@ -135,5 +135,7 @@ def parse_query_parameters(params)
Rack::Utils.parse_nested_query(params)
end
end
+
+ ::ActionView::Base.send :include, self
end
end
@@ -26,5 +26,3 @@
# load all fixtures
ActiverecordTestConnector::Fixtures.create_fixtures \
ActiverecordTestConnector::FIXTURES_PATH, ActiveRecord::Base.connection.tables
-
-WillPaginate::ActiveRecord.setup
@@ -1,9 +1,8 @@
require 'spec_helper'
require 'will_paginate/active_record'
require File.expand_path('../activerecord_test_connector', __FILE__)
-ActiverecordTestConnector.setup
-WillPaginate::ActiveRecord.setup
+ActiverecordTestConnector.setup
abort unless ActiverecordTestConnector.able_to_connect
describe WillPaginate::ActiveRecord do

0 comments on commit 4d260bc

Please sign in to comment.