Class: DmPagination::Paginator::Base
- Inherits:
-
Object
- Object
- DmPagination::Paginator::Base
- Defined in:
- lib/dm-pagination/paginator.rb
Instance Attribute Summary collapse
-
#num_pages ⇒ Object
readonly
Returns the value of attribute num_pages.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(collection, options) ⇒ Base
constructor
A new instance of Base.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to?(*args, &block) ⇒ Boolean
- #to_json ⇒ Object
Constructor Details
#initialize(collection, options) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/dm-pagination/paginator.rb', line 6 def initialize(collection, ) @proxy_collection = collection order = [:order] @page = ([:page] || 1).to_i @per_page = ([:per_page] || 10).to_i @num_pages = (@proxy_collection.count + @per_page - 1) / @per_page @offset = (@page - 1)*@per_page @collection = collection.all(:offset => @offset, :limit => @per_page) @collection = @collection.all(:order => order) if order end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
27 28 29 |
# File 'lib/dm-pagination/paginator.rb', line 27 def method_missing(method, *args, &block) @collection.send(method, *args, &block) end |
Instance Attribute Details
#num_pages ⇒ Object (readonly)
Returns the value of attribute num_pages.
4 5 6 |
# File 'lib/dm-pagination/paginator.rb', line 4 def num_pages @num_pages end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
4 5 6 |
# File 'lib/dm-pagination/paginator.rb', line 4 def page @page end |
Instance Method Details
#count ⇒ Object
19 20 21 |
# File 'lib/dm-pagination/paginator.rb', line 19 def count [0, [@proxy_collection.count - @offset, @per_page].min].max end |
#respond_to?(*args, &block) ⇒ Boolean
23 24 25 |
# File 'lib/dm-pagination/paginator.rb', line 23 def respond_to?(*args, &block) super || @collection.send(:respond_to?, *args, &block) end |
#to_json ⇒ Object
31 32 33 |
# File 'lib/dm-pagination/paginator.rb', line 31 def to_json @collection.to_json end |