Module: PaginationScope
- Defined in:
- lib/pagination_scope.rb
Defined Under Namespace
Modules: Extention Classes: Pagination
Constant Summary collapse
- VERSION =
'0.1.2'
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pagination_scope.rb', line 7 def included(base) base.class_eval do named_scope :paginate, (proc do |*args| = args.last.is_a?(Hash) ? args.pop : {} page = [(args.shift || .delete(:page) || 1).to_i - 1, 0].max per_page = args.shift || .delete(:per_page) || 10 [:extend] = PaginationScope::Extention if per_page < 0 per_page = -per_page [:order] ||= "#{table_name}.id ASC" [:order].gsub!(/\b(DESC|ASC)\b/i){ case $1.upcase when 'DESC'; 'ASC' when 'ASC'; 'DESC' end } end .merge :offset => per_page*(page), :limit => per_page end) end end |