Class: ActiveResource::Pagination::PagingFormatter
- Inherits:
-
Object
- Object
- ActiveResource::Pagination::PagingFormatter
- Includes:
- Formats::JsonFormat
- Defined in:
- lib/active_resource/pagination.rb
Overview
PagingFormatter expects a JSON response that looks like this (for a resource named “posts”): {
"total_pages": 5,
"current_page": 1,
"posts": [{
"id": 1
}]
}
Instance Attribute Summary collapse
-
#collection_name ⇒ Object
Returns the value of attribute collection_name.
Instance Method Summary collapse
- #decode(json) ⇒ Object
-
#initialize(name) ⇒ PagingFormatter
constructor
A new instance of PagingFormatter.
Constructor Details
#initialize(name) ⇒ PagingFormatter
Returns a new instance of PagingFormatter.
25 26 27 |
# File 'lib/active_resource/pagination.rb', line 25 def initialize(name) self.collection_name = name end |
Instance Attribute Details
#collection_name ⇒ Object
Returns the value of attribute collection_name.
23 24 25 |
# File 'lib/active_resource/pagination.rb', line 23 def collection_name @collection_name end |
Instance Method Details
#decode(json) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/active_resource/pagination.rb', line 29 def decode(json) = super(json) if .is_a?(Hash) && ['total_pages'] list = PagedArray.new([collection_name]) list.total_pages = ['total_pages'] list.current_page = ['current_page'] list elsif .is_a?(Array) list = PagedArray.new() list.total_pages = 1 list.current_page = 1 list else end end |