Class: NoyoFulfillment::ApiResourceCollection
- Defined in:
- lib/noyo_fulfillment/models/api_resource_collection.rb
Instance Attribute Summary collapse
-
#page_number ⇒ Object
Returns the value of attribute page_number.
-
#records ⇒ Object
Returns the value of attribute records.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #first ⇒ Object
-
#initialize(records, page_number = 0) ⇒ ApiResourceCollection
constructor
A new instance of ApiResourceCollection.
- #next_page ⇒ Object
- #size ⇒ Object (also: #count, #length)
Methods inherited from BaseModel
#==, #attributes, class_name, #excluded_attributes, #inspect, #synced_attributes, #to_h, #update_attrs
Constructor Details
#initialize(records, page_number = 0) ⇒ ApiResourceCollection
Returns a new instance of ApiResourceCollection.
13 14 15 16 17 |
# File 'lib/noyo_fulfillment/models/api_resource_collection.rb', line 13 def initialize(records, page_number = 0) @records = records @page_number = page_number super(records: records, page_number: page_number) end |
Instance Attribute Details
#page_number ⇒ Object
Returns the value of attribute page_number.
7 8 9 |
# File 'lib/noyo_fulfillment/models/api_resource_collection.rb', line 7 def page_number @page_number end |
#records ⇒ Object
Returns the value of attribute records.
7 8 9 |
# File 'lib/noyo_fulfillment/models/api_resource_collection.rb', line 7 def records @records end |
Instance Method Details
#[](key) ⇒ Object
27 28 29 |
# File 'lib/noyo_fulfillment/models/api_resource_collection.rb', line 27 def [](key) records[key] end |
#first ⇒ Object
31 32 33 |
# File 'lib/noyo_fulfillment/models/api_resource_collection.rb', line 31 def first records.first end |
#next_page ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/noyo_fulfillment/models/api_resource_collection.rb', line 19 def next_page raise "Invalid number of records: #{records.size}" if !records.size.positive? klass = records.first.class next_page_number = page_number + 1 klass.all(next_page_number) end |
#size ⇒ Object Also known as: count, length
35 36 37 |
# File 'lib/noyo_fulfillment/models/api_resource_collection.rb', line 35 def size records.size end |