Class: Yookassa::Entities::Collection
- Inherits:
-
Object
- Object
- Yookassa::Entities::Collection
- Includes:
- Enumerable
- Defined in:
- lib/yookassa/entities/collection.rb
Overview
Paginated collection of entities with cursor-based navigation.
Includes Enumerable so standard methods (+map+, select, first, etc.)
work out of the box.
Instance Attribute Summary collapse
-
#items ⇒ Array<Entities::Base>
readonly
Wrapped entity objects.
-
#next_cursor ⇒ String?
readonly
Cursor for fetching the next page.
Instance Method Summary collapse
-
#each {|entity| ... } ⇒ Object
Yields each entity in the collection.
-
#empty? ⇒ Boolean
trueif the collection has no items. -
#has_next? ⇒ Boolean
trueif more pages are available. -
#initialize(items:, next_cursor: nil, entity_class: Entities::Base) ⇒ Collection
constructor
A new instance of Collection.
-
#size ⇒ Integer
(also: #length)
Number of items in this page.
Constructor Details
#initialize(items:, next_cursor: nil, entity_class: Entities::Base) ⇒ Collection
27 28 29 30 |
# File 'lib/yookassa/entities/collection.rb', line 27 def initialize(items:, next_cursor: nil, entity_class: Entities::Base) @items = items.map { |item| entity_class.new(item) } @next_cursor = next_cursor end |
Instance Attribute Details
#items ⇒ Array<Entities::Base> (readonly)
19 20 21 |
# File 'lib/yookassa/entities/collection.rb', line 19 def items @items end |
#next_cursor ⇒ String? (readonly)
22 23 24 |
# File 'lib/yookassa/entities/collection.rb', line 22 def next_cursor @next_cursor end |
Instance Method Details
#each {|entity| ... } ⇒ Object
Yields each entity in the collection.
36 37 38 |
# File 'lib/yookassa/entities/collection.rb', line 36 def each(&) @items.each(&) end |
#empty? ⇒ Boolean
47 48 49 |
# File 'lib/yookassa/entities/collection.rb', line 47 def empty? @items.empty? end |
#has_next? ⇒ Boolean
52 53 54 |
# File 'lib/yookassa/entities/collection.rb', line 52 def has_next? !@next_cursor.to_s.empty? end |
#size ⇒ Integer Also known as: length
41 42 43 |
# File 'lib/yookassa/entities/collection.rb', line 41 def size @items.size end |