Module: DataMapper::Paginator
- Defined in:
- lib/dm-paginator/main.rb,
lib/dm-paginator/control.rb,
lib/dm-paginator/default.rb,
lib/dm-paginator/version.rb,
lib/dm-paginator/paginator.rb,
lib/dm-paginator/control/all.rb,
lib/dm-paginator/control/elastic.rb,
lib/dm-paginator/control/jumping.rb,
lib/dm-paginator/control/sliding.rb,
lib/dm-paginator/control/control_helper_abstract.rb
Defined Under Namespace
Modules: ControlHelper, ControlHelperAbstract Classes: Control, Main
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Attribute Summary collapse
-
#paginator ⇒ Object
Returns the value of attribute paginator.
Class Method Summary collapse
Instance Method Summary collapse
-
#limit(options = {}) ⇒ Collection
Limit results.
-
#limit_page(page = nil, options = {}) ⇒ Collection
Limit results by page.
Instance Attribute Details
#paginator ⇒ Object
Returns the value of attribute paginator.
3 4 5 |
# File 'lib/dm-paginator/paginator.rb', line 3 def paginator @paginator end |
Class Method Details
.default ⇒ Object
10 11 12 |
# File 'lib/dm-paginator/default.rb', line 10 def self.default @default end |
Instance Method Details
#limit(options = {}) ⇒ Collection
Limit results.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dm-paginator/paginator.rb', line 10 def limit = {} # Remove this key if we come from limit_page method. page = .delete :page query = .dup collection = new_collection scoped_query( = { :limit => [:limit], :offset => [:offset], :order => [[:order]] }.merge( query ) ) .merge! :count => calculate_total_records( query ), :page => page collection.paginator = DataMapper::Paginator::Main.new collection end |
#limit_page(page = nil, options = {}) ⇒ Collection
Limit results by page.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dm-paginator/paginator.rb', line 30 def limit_page page = nil, = {} if page.is_a?( Hash ) = page else [:page] = page.to_i end [:page] = [:page].to_i > 0 ? [:page] : DataMapper::Paginator.default[:page] [:limit] = [:limit].to_i || DataMapper::Paginator.default[:limit] [:offset] = [:limit] * ( [:page] - 1 ) [:order] = [:order] || DataMapper::Paginator.default[:order] limit end |