Class: DmPagination::Paginator::Base
- Inherits:
-
Object
- Object
- DmPagination::Paginator::Base
show all
- Defined in:
- lib/dm-pagination/paginator.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(collection, options) ⇒ Base
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/dm-pagination/paginator.rb', line 6
def initialize(collection, options)
@proxy_collection = collection
order = options[:order]
@page = (options[:page] || 1).to_i
@per_page = (options[: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
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
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
|