Class: Alephant::Lookup::LookupQuery

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/alephant/lookup/lookup_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name, component_id, opts, batch_version) ⇒ LookupQuery



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/alephant/lookup/lookup_query.rb', line 11

def initialize(table_name, component_id, opts, batch_version)
  options = {}
  options[:endpoint] = ENV['AWS_DYNAMO_DB_ENDPOINT'] if ENV['AWS_DYNAMO_DB_ENDPOINT']
  @client            = Aws::DynamoDB::Client.new(options)
  @table_name        = table_name
  @lookup_location   = LookupLocation.new(component_id, opts, batch_version)

  logger.info(
    "event"        => "LookupQueryInitialized",
    "tableName"    => table_name,
    "componentId"  => component_id,
    "location"     => lookup_location,
    "batchVersion" => batch_version,
    "method"       => "#{self.class}#initialize"
  )
end

Instance Attribute Details

#lookup_locationObject (readonly)

Returns the value of attribute lookup_location.



9
10
11
# File 'lib/alephant/lookup/lookup_query.rb', line 9

def lookup_location
  @lookup_location
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



9
10
11
# File 'lib/alephant/lookup/lookup_query.rb', line 9

def table_name
  @table_name
end

Instance Method Details

#run!Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/alephant/lookup/lookup_query.rb', line 28

def run!
  lookup_location.tap do |l|
    l.location = s3_location_from(
      @client.query(to_q)
    ).tap do |loc|
      logger.info(
        "event"    => "S3LocationRetrieved",
        "location" => loc,
        "method"   => "#{self.class}#run!"
      )
    end
  end
end