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



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

def initialize(table_name)
  options = {}
  options.merge!({endpoint: ENV['AWS_DYNAMO_DB_ENDPOINT']}) if ENV['AWS_DYNAMO_DB_ENDPOINT']
  @mutex      = Mutex.new
  @client     = Aws::DynamoDB::Client.new(options)
  @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



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

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