Class: Magento::RecordCollection
- Inherits:
-
Object
- Object
- Magento::RecordCollection
- Extended by:
- Forwardable
- Defined in:
- lib/magento/record_collection.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#search_criteria ⇒ Object
readonly
Returns the value of attribute search_criteria.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(items:, total_count: nil, search_criteria: nil) ⇒ RecordCollection
constructor
A new instance of RecordCollection.
- #last_page? ⇒ Boolean
-
#next_page ⇒ Object
Returns the number of the next page or nil when the current_page is the last page.
Constructor Details
#initialize(items:, total_count: nil, search_criteria: nil) ⇒ RecordCollection
Returns a new instance of RecordCollection.
10 11 12 13 14 |
# File 'lib/magento/record_collection.rb', line 10 def initialize(items:, total_count: nil, search_criteria: nil) @items = items || [] @total_count = total_count || @items.size @search_criteria = search_criteria || Magento::SearchCriterium.new end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
7 8 9 |
# File 'lib/magento/record_collection.rb', line 7 def items @items end |
#search_criteria ⇒ Object (readonly)
Returns the value of attribute search_criteria.
7 8 9 |
# File 'lib/magento/record_collection.rb', line 7 def search_criteria @search_criteria end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
7 8 9 |
# File 'lib/magento/record_collection.rb', line 7 def total_count @total_count end |
Class Method Details
.from_magento_response(response, model:, iterable_field: 'items') ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/magento/record_collection.rb', line 38 def from_magento_response(response, model:, iterable_field: 'items') Magento::RecordCollection.new( items: response[iterable_field]&.map { |item| model.build(item) }, total_count: response['total_count'], search_criteria: Magento::SearchCriterium.build(response['search_criteria']) ) end |
Instance Method Details
#last_page? ⇒ Boolean
26 27 28 |
# File 'lib/magento/record_collection.rb', line 26 def last_page? current_page * page_size >= total_count end |
#next_page ⇒ Object
Returns the number of the next page or nil when the current_page is the last page
33 34 35 |
# File 'lib/magento/record_collection.rb', line 33 def next_page current_page + 1 unless last_page? end |