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.
-
#scope_id ⇒ Object
readonly
Returns the value of attribute scope_id.
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.
8 9 10 11 12 13 14 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 8 def initialize(query = {}) @query = query.dup @resource_class = @query.delete(:resource_class) @resource_url = @query.delete(:resource_url) @scope_id = @query.delete(:scope_id) @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 @meta 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 |
#scope_id ⇒ Object (readonly)
Returns the value of attribute scope_id.
5 6 7 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 5 def scope_id @scope_id end |
Instance Method Details
#each_item ⇒ Object
20 21 22 23 24 25 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 20 def each_item return enum_for :each_item unless block_given? begin each { |record| yield record } end while !self.next.empty? end |
#first ⇒ Object
27 28 29 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 27 def first loaded? ? load_page_url(:first) : load! end |
#last ⇒ Object
39 40 41 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 39 def last load_page_url :last end |
#loaded? ⇒ Boolean
16 17 18 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 16 def loaded? @loaded end |
#next ⇒ Object
31 32 33 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 31 def next load_page_url :next end |
#previous ⇒ Object
35 36 37 |
# File 'lib/vzaar_api/lib/paged_resource.rb', line 35 def previous load_page_url :previous end |