Class: VzaarApi::Lib::PagedResource
- Inherits:
-
Object
- Object
- VzaarApi::Lib::PagedResource
- Defined in:
- lib/vzaar_api/lib/paged_resource.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#resource_class ⇒ Object
readonly
Returns the value of attribute resource_class.
-
#resource_url ⇒ Object
readonly
Returns the value of attribute resource_url.
Instance Method Summary collapse
- #each_item ⇒ Object
- #first ⇒ Object
-
#initialize(query = {}) ⇒ PagedResource
constructor
A new instance of PagedResource.
- #last ⇒ Object
- #loaded? ⇒ Boolean
- #next ⇒ Object
- #previous ⇒ Object
Constructor Details
#initialize(query = {}) ⇒ PagedResource
Returns a new instance of PagedResource.
7 8 9 10 11 12 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 7 def initialize(query = {}) @query = query.dup @resource_class = @query.delete(:resource_class) @resource_url = @query.delete(:resource_url) @loaded = false end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
5 6 7 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 5 def collection @collection end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
5 6 7 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 5 def end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
5 6 7 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 5 def query @query end |
#resource_class ⇒ Object (readonly)
Returns the value of attribute resource_class.
5 6 7 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 5 def resource_class @resource_class end |
#resource_url ⇒ Object (readonly)
Returns the value of attribute resource_url.
5 6 7 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 5 def resource_url @resource_url end |
Instance Method Details
#each_item ⇒ Object
18 19 20 21 22 23 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 18 def each_item return enum_for :each_item unless block_given? begin each { |record| yield record } end while !self.next.empty? end |
#first ⇒ Object
25 26 27 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 25 def first loaded? ? load_page_url(:first) : load! end |
#last ⇒ Object
37 38 39 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 37 def last load_page_url :last end |
#loaded? ⇒ Boolean
14 15 16 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 14 def loaded? @loaded end |
#next ⇒ Object
29 30 31 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 29 def next load_page_url :next end |
#previous ⇒ Object
33 34 35 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 33 def previous load_page_url :previous end |