Class: Alephant::Lookup::LookupHelper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lookup_table) ⇒ LookupHelper

Returns a new instance of LookupHelper.



13
14
15
16
17
18
19
20
21
# File 'lib/alephant/lookup/lookup_helper.rb', line 13

def initialize(lookup_table)
  @lookup_table = lookup_table

  logger.info(
    "event"     => "LookupHelperInitialized",
    "tableName" => lookup_table.table_name,
    "method"    => "#{self.class}#initialize"
  )
end

Instance Attribute Details

#lookup_tableObject (readonly)

Returns the value of attribute lookup_table.



11
12
13
# File 'lib/alephant/lookup/lookup_helper.rb', line 11

def lookup_table
  @lookup_table
end

Instance Method Details

#read(id, opts, batch_version) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/alephant/lookup/lookup_helper.rb', line 23

def read(id, opts, batch_version)
  LookupQuery.new(lookup_table.table_name, id, opts, batch_version).run!.tap do
    logger.info(
      "event"        => "LookupQuery",
      "tableName"    => lookup_table.table_name,
      "id"           => id,
      "opts"         => opts,
      "batchVersion" => batch_version,
      "method"       => "#{self.class}#read"
    )
  end
end

#truncate!Object



55
56
57
# File 'lib/alephant/lookup/lookup_helper.rb', line 55

def truncate!
  @lookup_table.truncate!
end

#write(id, opts, batch_version, location) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/alephant/lookup/lookup_helper.rb', line 36

def write(id, opts, batch_version, location)
  LookupLocation.new(id, opts, batch_version, location).tap do |l|
    lookup_table.write(
      l.component_key,
      l.batch_version,
      l.location
    ).tap do
      logger.info(
        "event"        => "LookupLocationUpdated",
        "location"     => location,
        "id"           => id,
        "opts"         => opts,
        "batchVersion" => batch_version,
        "method"       => "#{self.class}#write"
      )
    end
  end
end