Skip to content

Commit

Permalink
change scope to class method
Browse files Browse the repository at this point in the history
  • Loading branch information
kolodovskyi committed Sep 11, 2013
1 parent 6471b93 commit 92052ee
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/kaminari/models/active_record_model_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ module ActiveRecordModelExtension

included do
self.send(:include, Kaminari::ConfigurationMethods)
end

module ClassMethods
# Fetch the values at the specified page number
# Model.page(5)
self.scope Kaminari.config.page_method_name, Proc.new {|num|
limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1))
} do
include Kaminari::ActiveRecordRelationMethods
include Kaminari::PageScopeMethods
define_method(Kaminari.config.page_method_name) do |num = nil|
limit(default_per_page).offset(default_per_page * ([num.to_i, 1].max - 1)).extending do
include Kaminari::ActiveRecordRelationMethods
include Kaminari::PageScopeMethods
end
end
end
end
Expand Down

0 comments on commit 92052ee

Please sign in to comment.