Class: ApiOnlyPagination::Pagination
- Inherits:
-
Object
- Object
- ApiOnlyPagination::Pagination
- Defined in:
- lib/api_only_pagination/pagination.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(collection, params = {}) ⇒ Pagination
constructor
A new instance of Pagination.
- #metadata ⇒ Object
- #results ⇒ Object
Constructor Details
#initialize(collection, params = {}) ⇒ Pagination
Returns a new instance of Pagination.
7 8 9 10 |
# File 'lib/api_only_pagination/pagination.rb', line 7 def initialize(collection, params = {}) @collection = collection @params = params.merge(count: collection.count) end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
5 6 7 |
# File 'lib/api_only_pagination/pagination.rb', line 5 def collection @collection end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/api_only_pagination/pagination.rb', line 5 def params @params end |
Instance Method Details
#metadata ⇒ Object
12 13 14 |
# File 'lib/api_only_pagination/pagination.rb', line 12 def @metadata ||= ApiOnlyPagination::Paginate.new(params[:page], params[:per_page], params[:count]) end |
#results ⇒ Object
16 17 18 19 20 |
# File 'lib/api_only_pagination/pagination.rb', line 16 def results collection .limit(.per_page) .offset(.offset) end |