Class: Shoryuken::Later::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/shoryuken/later/client.rb

Constant Summary collapse

@@tables =
{}

Class Method Summary collapse

Class Method Details

.create_item(table, item) ⇒ Object



18
19
20
21
22
23
# File 'lib/shoryuken/later/client.rb', line 18

def create_item(table, item)
  item['id'] ||= SecureRandom.uuid
  
  ddb.put_item(table_name: table, item: item,
               expected: {id: {exists: false}})
end

.ddbObject



30
31
32
# File 'lib/shoryuken/later/client.rb', line 30

def ddb
  @ddb ||= Aws::DynamoDB::Client.new
end

.delete_item(table, item) ⇒ Object



25
26
27
28
# File 'lib/shoryuken/later/client.rb', line 25

def delete_item(table, item)
  ddb.delete_item(table_name: table, key: {id: item['id']},
                  expected: {id: {value: item['id'], exists: true}})
end

.first_item(table, filter = nil) ⇒ Object



13
14
15
16
# File 'lib/shoryuken/later/client.rb', line 13

def first_item(table, filter=nil)
  result = ddb.scan(table_name: table, limit: 1, scan_filter: filter)
  result.items.first if result
end

.tables(table) ⇒ Object



9
10
11
# File 'lib/shoryuken/later/client.rb', line 9

def tables(table)
  @@tables[table] ||= ddb.describe_table(table_name: table)
end