Class: Moe::Sequence::ItemFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/moe/sequence/item_fetcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name, owner_id, uid) ⇒ ItemFetcher

Returns a new instance of ItemFetcher.



7
8
9
10
11
12
13
14
# File 'lib/moe/sequence/item_fetcher.rb', line 7

def initialize(table_name, owner_id, uid)
  @dyna = Dyna.new
  @items = []
  @owner_id = owner_id
  @sequence_id = 1
  @table_name = table_name
  @uid = uid
end

Instance Attribute Details

#dynaObject

Returns the value of attribute dyna.



4
5
6
# File 'lib/moe/sequence/item_fetcher.rb', line 4

def dyna
  @dyna
end

#itemsObject

Returns the value of attribute items.



4
5
6
# File 'lib/moe/sequence/item_fetcher.rb', line 4

def items
  @items
end

#owner_idObject (readonly)

Returns the value of attribute owner_id.



5
6
7
# File 'lib/moe/sequence/item_fetcher.rb', line 5

def owner_id
  @owner_id
end

#sequence_idObject

Returns the value of attribute sequence_id.



4
5
6
# File 'lib/moe/sequence/item_fetcher.rb', line 4

def sequence_id
  @sequence_id
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



5
6
7
# File 'lib/moe/sequence/item_fetcher.rb', line 5

def table_name
  @table_name
end

#uidObject (readonly)

Returns the value of attribute uid.



5
6
7
# File 'lib/moe/sequence/item_fetcher.rb', line 5

def uid
  @uid
end

Instance Method Details

#fetch(limit) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/moe/sequence/item_fetcher.rb', line 16

def fetch(limit)
  request = {
    request_items: {
      table_name => { keys: [] }
    }
  }
  keys = request[:request_items][table_name][:keys]

  limit.times do
    keys << dyna.explode( Locksmith.key(owner_id, sequence_id, uid) )

    self.sequence_id += 1
  end

  munge dyna.dynamodb.batch_get_item(request)
end