Class: DynamodbRecord::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/dynamodb_record/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(pager, base_object) ⇒ Collection

attr_reader :last_evaluated_key



9
10
11
12
13
14
15
16
# File 'lib/dynamodb_record/collection.rb', line 9

def initialize(pager, base_object)
  @base_object = base_object
  @pager = pager
  @klass = @pager.klass
  @options = @pager.options
  items = @pager.items
  @items = items.map { |item| @klass.send(:from_database, item) }
end

Instance Method Details

#eachObject



18
19
20
# File 'lib/dynamodb_record/collection.rb', line 18

def each(&)
  @items.each(&)
end

#last_evaluated_keyObject



22
23
24
# File 'lib/dynamodb_record/collection.rb', line 22

def last_evaluated_key
  @pager.last_evaluated_key
end

#next_pageObject



30
31
32
# File 'lib/dynamodb_record/collection.rb', line 30

def next_page
  self.class.new(@pager.next_page, @base_object)
end

#next_page?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/dynamodb_record/collection.rb', line 26

def next_page?
  @pager ? @pager.next_page? : false
end

#page(last_key) ⇒ Object



34
35
36
# File 'lib/dynamodb_record/collection.rb', line 34

def page(last_key)
  self.class.new(@pager.next_page(last_key), @base_object) if last_key
end