Class: Shoryuken::Later::Client
- Inherits:
-
Object
- Object
- Shoryuken::Later::Client
- Defined in:
- lib/shoryuken/later/client.rb
Constant Summary collapse
- @@tables =
{}
Class Method Summary collapse
- .create_item(table, item) ⇒ Object
- .ddb ⇒ Object
- .delete_item(table, item) ⇒ Object
- .first_item(table, filter = nil) ⇒ Object
- .tables(table) ⇒ Object
Class Method Details
.create_item(table, item) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/shoryuken/later/client.rb', line 22 def create_item(table, item) item['id'] ||= SecureRandom.uuid ddb.put_item(table_name: table, item: item, expected: {id: {exists: false}}) end |
.ddb ⇒ Object
34 35 36 |
# File 'lib/shoryuken/later/client.rb', line 34 def ddb @ddb ||= Aws::DynamoDB::Client.new end |
.delete_item(table, item) ⇒ Object
29 30 31 32 |
# File 'lib/shoryuken/later/client.rb', line 29 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 17 18 19 20 |
# File 'lib/shoryuken/later/client.rb', line 13 def first_item(table, filter=nil) item = nil response = ddb.scan(table_name: table, limit: 1, scan_filter: filter) response.each do |result| item = result.items.first and break end item 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 |