Sha256: 8fe9364005a06715993b53bff4f27bd0f5923a038c9bb23c192a4cc7870492e4

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require "alephant/lookup/lookup_table"
require "alephant/lookup/lookup_query"

require 'alephant/logger'

module Alephant
  module Lookup
    class LookupHelper
      include Logger

      attr_reader :lookup_table

      def initialize(lookup_table, logger)
        Logger.set_logger(logger)

        logger.info "LookupHelper#initialize(#{lookup_table.table_name})"

        @lookup_table = lookup_table
        @lookup_table.create
      end

      def read(id, opts, batch_version)
        logger.info "LookupHelper#read(#{id}, #{opts}, #{batch_version})"

        LookupQuery.new(lookup_table.table_name, id, opts, batch_version).run!
      end

      def write(id, opts, batch_version, location)
        logger.info "LookupHelper#write(#{id}, #{opts}, #{batch_version}, #{location})"

        LookupLocation.new(id, opts, batch_version, location).tap do |l|
          lookup_table.table.batch_put([
            {
              :component_key => l.component_key,
              :batch_version => l.batch_version,
              :location      => l.location
            }
          ])
        end
      end

      def truncate!
        @lookup_table.truncate!
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alephant-lookup-0.2.0 lib/alephant/lookup/lookup_helper.rb