Class: Alephant::Lookup::LookupTable

Inherits:
Support::DynamoDB::Table
  • Object
show all
Includes:
Logger
Defined in:
lib/alephant/lookup/lookup_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name) ⇒ LookupTable

Returns a new instance of LookupTable.



14
15
16
17
18
19
20
21
22
23
# File 'lib/alephant/lookup/lookup_table.rb', line 14

def initialize(table_name)
  @mutex      = Mutex.new
  @client     = AWS::DynamoDB::Client::V20120810.new
  @table_name = table_name
  logger.info(
    "event"     => "LookupTableInitialized",
    "tableName" => table_name,
    "method"    => "#{self.class}#initialize"
  )
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



12
13
14
# File 'lib/alephant/lookup/lookup_table.rb', line 12

def client
  @client
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



12
13
14
# File 'lib/alephant/lookup/lookup_table.rb', line 12

def table_name
  @table_name
end

Instance Method Details

#write(component_key, version, location) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/alephant/lookup/lookup_table.rb', line 25

def write(component_key, version, location)
  client.put_item({
    :table_name => table_name,
    :item => {
      'component_key' => {
        'S' => component_key.to_s
      },
      'batch_version' => {
        'N' => version.to_s
      },
      'location' => {
        'S' => location.to_s
      }
    }
  }).tap do
    logger.info(
      "event"        => "LookupLocationWritten",
      "componentKey" => component_key,
      "version"      => version,
      "location"     => location,
      "method"       => "#{self.class}#write"
    )
  end
end