Class: DynamodbRecord::HasManyThroughCollection

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

Overview

Dynamodb::HasManyThroughCollection is a class that represent a ManyToManyCollection

Instance Method Summary collapse

Constructor Details

#initialize(pager, base_object) ⇒ HasManyThroughCollection

Returns a new instance of HasManyThroughCollection.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dynamodb_record/has_many_through_collection.rb', line 8

def initialize(pager, base_object)
  @base_object = base_object
  @pager = pager
  @klass = @pager.klass
  @options = @pager.options
  @items = []
  @pager.items.each do |item|
    # p item
    object = @klass.client.get_item(
      table_name: @klass.table_name,
      key: {id: item["#{@klass.to_s.downcase}_id"]}
    )
    @items << @klass.send(:from_database, object.item)
  end
end

Instance Method Details

#eachObject



24
25
26
# File 'lib/dynamodb_record/has_many_through_collection.rb', line 24

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

#last_evaluated_keyObject



28
29
30
# File 'lib/dynamodb_record/has_many_through_collection.rb', line 28

def last_evaluated_key
  @pager.last_evaluated_key
end

#next_pageObject



36
37
38
# File 'lib/dynamodb_record/has_many_through_collection.rb', line 36

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

#next_page?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/dynamodb_record/has_many_through_collection.rb', line 32

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

#page(last_key) ⇒ Object



40
41
42
# File 'lib/dynamodb_record/has_many_through_collection.rb', line 40

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