Module: Oedipus::DataMapper::Pagination
- Included in:
- Index
- Defined in:
- lib/oedipus/data_mapper/pagination.rb
Instance Method Summary collapse
- #build_pager(results, options) ⇒ Object
- #extract_pager_options(filters) ⇒ Object
- #pageable? ⇒ Boolean
Instance Method Details
#build_pager(results, options) ⇒ Object
42 43 44 45 |
# File 'lib/oedipus/data_mapper/pagination.rb', line 42 def build_pager(results, ) return unless pageable? && Hash === ::DataMapper::Pager.new(.merge(total: results[:total_found])) end |
#extract_pager_options(filters) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/oedipus/data_mapper/pagination.rb', line 17 def (filters) return unless pageable? = filters.last pager = .delete(:pager) unless pager.nil? return unless page = pager[:page] page = [page.to_i, 1].max per_page = pager.fetch(:per_page, ::DataMapper::Pagination.defaults[:per_page]).to_i page_param = pager.fetch(:page_param, ::DataMapper::Pagination.defaults[:page_param]) [:limit] ||= per_page [:offset] ||= (page - 1) * per_page pager.merge( page_param => page, :page_param => page_param, :limit => [:limit].to_i, :offset => [:offset].to_i ) end end |
#pageable? ⇒ Boolean
13 14 15 |
# File 'lib/oedipus/data_mapper/pagination.rb', line 13 def pageable? defined? ::DataMapper::Pagination end |