class Corpshort::Backends::Dynamodb

Public Class Methods

new(table:, region:) click to toggle source
# File lib/corpshort/backends/dynamodb.rb, line 10
def initialize(table:, region:)
  @table_name = table
  @region = region
end

Public Instance Methods

dynamodb() click to toggle source
# File lib/corpshort/backends/dynamodb.rb, line 19
def dynamodb
  @dynamodb ||= Aws::DynamoDB::Resource.new(region: @region)
end
table() click to toggle source
# File lib/corpshort/backends/dynamodb.rb, line 15
def table
  @table ||= dynamodb.table(@table_name)
end

Private Instance Methods

parse_token(token) click to toggle source
# File lib/corpshort/backends/dynamodb.rb, line 102
def parse_token(token)
  if token.nil?
    return [Time.now, nil]
  end
  partition, name, ts = token.split(?:,3)
  [Time.strptime(partition, '%Y-%m'), ts ? {"updated_at_partition" => partition, "updated_at" => ts, "name" => name} : nil]
end
ts_partition(time) click to toggle source
# File lib/corpshort/backends/dynamodb.rb, line 110
def ts_partition(time)
  time.strftime('%Y-%m')
end