Class: DynamoRecord::Collection
- Inherits:
-
Array
- Object
- Array
- DynamoRecord::Collection
- Defined in:
- lib/dynamo_record/collection.rb
Instance Method Summary collapse
- #each_page(&block) ⇒ Object
-
#initialize(pager = nil, klass = nil) ⇒ Collection
constructor
A new instance of Collection.
- #last_evaluated_key ⇒ Object
- #last_page? ⇒ Boolean
- #next_page ⇒ Object
- #next_page? ⇒ Boolean
Constructor Details
#initialize(pager = nil, klass = nil) ⇒ Collection
Returns a new instance of Collection.
4 5 6 7 8 9 10 |
# File 'lib/dynamo_record/collection.rb', line 4 def initialize(pager = nil, klass = nil) if pager && klass @pager = pager @klass = klass replace @pager.items.map { |item| klass.send(:from_database, item) } end end |
Instance Method Details
#each_page(&block) ⇒ Object
25 26 27 28 29 |
# File 'lib/dynamo_record/collection.rb', line 25 def each_page(&block) @pager.each do |page| yield self.class.new(page, @klass) end end |
#last_evaluated_key ⇒ Object
31 32 33 |
# File 'lib/dynamo_record/collection.rb', line 31 def last_evaluated_key @pager.last_evaluated_key end |
#last_page? ⇒ Boolean
16 17 18 |
# File 'lib/dynamo_record/collection.rb', line 16 def last_page? @pager ? @pager.last_page? : true end |
#next_page ⇒ Object
20 21 22 23 |
# File 'lib/dynamo_record/collection.rb', line 20 def next_page return self.class.new(@pager.next_page, @klass) if @pager.next_page? self.class.new end |
#next_page? ⇒ Boolean
12 13 14 |
# File 'lib/dynamo_record/collection.rb', line 12 def next_page? @pager ? @pager.next_page? : false end |