class Alephant::Lookup::LookupHelper

Attributes

config[R]
lookup_table[R]

Public Class Methods

new(lookup_table, config={}) click to toggle source
# File lib/alephant/lookup/lookup_helper.rb, line 14
def initialize(lookup_table, config={})
  @lookup_table = lookup_table
  @config = config

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

Public Instance Methods

read(id, opts, batch_version) click to toggle source
# File lib/alephant/lookup/lookup_helper.rb, line 25
def read(id, opts, batch_version)
  LookupCache.new(config).get(component_cache_key(id, opts, batch_version)) do
    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
end
truncate!() click to toggle source
# File lib/alephant/lookup/lookup_helper.rb, line 59
def truncate!
  lookup_table.truncate!
end
write(id, opts, batch_version, location) click to toggle source
# File lib/alephant/lookup/lookup_helper.rb, line 40
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

Private Instance Methods

component_cache_key(id, opts, batch_version) click to toggle source
# File lib/alephant/lookup/lookup_helper.rb, line 65
def component_cache_key(id, opts, batch_version)
  template_key(batch_version).gsub("{{COMPONENT_KEY}}") do |s|
    LookupLocation.new(id, opts, batch_version).component_key
  end
end
template_key(batch_version) click to toggle source
# File lib/alephant/lookup/lookup_helper.rb, line 71
def template_key(batch_version)
  "#{lookup_table.table_name}/{{COMPONENT_KEY}}/#{batch_version}"
end