Class: Alephant::Lookup::LookupHelper
- Inherits:
-
Object
- Object
- Alephant::Lookup::LookupHelper
- Includes:
- Logger
- Defined in:
- lib/alephant/lookup/lookup_helper.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#lookup_table ⇒ Object
readonly
Returns the value of attribute lookup_table.
Instance Method Summary collapse
-
#initialize(lookup_table, config = {}) ⇒ LookupHelper
constructor
A new instance of LookupHelper.
- #read(id, opts, batch_version) ⇒ Object
- #truncate! ⇒ Object
- #write(id, opts, batch_version, location) ⇒ Object
Constructor Details
#initialize(lookup_table, config = {}) ⇒ LookupHelper
Returns a new instance of LookupHelper.
14 15 16 17 18 19 20 21 22 23 |
# 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 |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
12 13 14 |
# File 'lib/alephant/lookup/lookup_helper.rb', line 12 def config @config end |
#lookup_table ⇒ Object (readonly)
Returns the value of attribute lookup_table.
12 13 14 |
# File 'lib/alephant/lookup/lookup_helper.rb', line 12 def lookup_table @lookup_table end |
Instance Method Details
#read(id, opts, batch_version) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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! ⇒ Object
59 60 61 |
# File 'lib/alephant/lookup/lookup_helper.rb', line 59 def truncate! lookup_table.truncate! end |
#write(id, opts, batch_version, location) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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 |