hecks-adapters-dynamodb 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d01eb0bda1da4c97e9d74b2a604a15f5f1b0e331
4
- data.tar.gz: 6fe760374898bcbcaccdedd5490df18a7fa3144a
3
+ metadata.gz: 793d73624fb70a03740bcae17bddc7bd171fbf4a
4
+ data.tar.gz: 5927e6b369fa8e0384a0f7b5dca632b4eeb1cd53
5
5
  SHA512:
6
- metadata.gz: a05df50649f0db09c57cf8781f2aab2d33381ccf2c3e644b71ff270eaacc272db1ff319fa96e8a97168d9ce67b5f72af03130dfb3f1b7cd8de72327277955f31
7
- data.tar.gz: 2eb7faf72e9b79139e7c573b81c7a8070dda4f2191681f68fd0fe5406389f44ca1c68da042f0d6af2bc639133ee370ab04213d852bdc2f4408c10552e2a41115
6
+ metadata.gz: 8db21a02be74ae87e912f3c194eb763c69bcc91759d5ae83aecab128f11b7d9e6b232db207ef436684dbb651fb8a8fe6eba06dadeadcef31324883ea9e983445
7
+ data.tar.gz: 9c193a8904ddb48c14968beb5aa9ea4553895b4a2a60d72b9cdfc5014f7cd6488e4f717619e1c4336cf2fffc2301f7e7daf335a80b4c1c7229f6db90d1cff923
@@ -1,33 +1,33 @@
1
- module Hecks
2
- module Adapters
3
- class DynamoDB
4
- module Commands
5
- class Create
6
- attr_reader :id
1
+ module HecksAdapters
2
+ class DynamoDB
3
+ module Commands
4
+ # Create a resource on DynamoDB
5
+ class Create
6
+ attr_reader :id
7
7
 
8
- def initialize(args, head, client)
9
- @args = args
10
- @head = head
11
- @client = client
12
- end
8
+ def initialize(args, head, client)
9
+ @args = args
10
+ @head = head
11
+ @client = client
12
+ end
13
+
14
+ def call
15
+ put_item
16
+ self
17
+ end
13
18
 
14
- def call
15
- put_item
16
- self
17
- end
19
+ private
18
20
 
19
- private
21
+ attr_reader :client, :args, :head
20
22
 
21
- attr_reader :client, :args, :head
23
+ def put_item
24
+ @id = args[:id]
25
+ result = client.put_item({
26
+ item: args,
27
+ return_consumed_capacity: 'TOTAL',
28
+ table_name: head.name
29
+ })
22
30
 
23
- def put_item
24
- @id = SecureRandom.uuid
25
- client.put_item({
26
- item: args.merge(id: @id),
27
- return_consumed_capacity: 'TOTAL',
28
- table_name: head.name
29
- })
30
- end
31
31
  end
32
32
  end
33
33
  end
@@ -1,29 +1,25 @@
1
- module Hecks
2
- module Adapters
3
- class DynamoDB
4
- module Commands
5
- class Delete
6
- def initialize(id, head, client)
7
- @head = head
8
- @id = id
9
- @client = client
10
- end
1
+ module HecksAdapters
2
+ class DynamoDB
3
+ module Commands
4
+ # Delete a resource on Dynamo DB
5
+ class Delete
6
+ def initialize(query, head, client)
7
+ @head = head
8
+ @query = query
9
+ @client = client
10
+ end
11
11
 
12
- def call
13
- delete_item
14
- self
15
- end
12
+ def call
13
+ delete_item
14
+ self
15
+ end
16
16
 
17
- private
17
+ private
18
18
 
19
- attr_reader :client, :head
19
+ attr_reader :client, :head, :query
20
20
 
21
- def delete_item
22
- client.delete_item(
23
- key: { "id" => @id },
24
- table_name: head.name
25
- )
26
- end
21
+ def delete_item
22
+ client.delete_item(key: query, table_name: head.name)
27
23
  end
28
24
  end
29
25
  end
data/lib/commands/read.rb CHANGED
@@ -1,37 +1,36 @@
1
- module Hecks
2
- module Adapters
3
- class DynamoDB
4
- module Commands
5
- class Read
6
- def initialize(id, head, client)
7
- @client = client
8
- @id = id
9
- @head = head
10
- end
1
+ module HecksAdapters
2
+ class DynamoDB
3
+ module Commands
4
+ # Read a resource on DynamoDB
5
+ class Read
6
+ def initialize(query, head, client)
7
+ @client = client
8
+ @query = query
9
+ @head = head
10
+ end
11
11
 
12
- def call
13
- result = get_item
14
- return nil if result.nil?
15
- PizzaBuilder::Domain::Pizzas.head.new(result)
16
- end
12
+ def call
13
+ result = get_item
14
+ return nil if result.nil?
15
+ PizzaBuilder::Domain::Pizzas.head.new(result)
16
+ end
17
17
 
18
- private
18
+ private
19
19
 
20
- attr_reader :client, :head
20
+ attr_reader :client, :head, :query
21
21
 
22
- def get_item
23
- symbolize(
24
- client.get_item(
25
- key: { id: @id },
26
- table_name: head.name
27
- ).item)
28
- end
22
+ def get_item
23
+ symbolize(
24
+ client.get_item(
25
+ key: query,
26
+ table_name: head.name
27
+ ).item)
28
+ end
29
29
 
30
- def symbolize(obj)
31
- return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = symbolize(v); memo} if obj.is_a? Hash
32
- return obj.inject([]){|memo,v | memo << symbolize(v); memo} if obj.is_a? Array
33
- return obj
34
- end
30
+ def symbolize(obj)
31
+ return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = symbolize(v); memo} if obj.is_a? Hash
32
+ return obj.inject([]){|memo,v | memo << symbolize(v); memo} if obj.is_a? Array
33
+ return obj
35
34
  end
36
35
  end
37
36
  end
@@ -1,38 +1,37 @@
1
- module Hecks
2
- module Adapters
3
- class DynamoDB
4
- module Commands
5
- class Update
6
- def initialize(id, attributes, head, client)
7
- @head = head
8
- @attributes = attributes
9
- @client = client
10
- @id = id
11
- end
1
+ module HecksAdapters
2
+ class DynamoDB
3
+ module Commands
4
+ # Update a resource on DynamoDB
5
+ class Update
6
+ def initialize(id, attributes, head, client)
7
+ @head = head
8
+ @attributes = attributes
9
+ @client = client
10
+ @id = id
11
+ end
12
12
 
13
- def call
14
- update_item
15
- self
16
- end
13
+ def call
14
+ update_item
15
+ self
16
+ end
17
17
 
18
- private
18
+ private
19
19
 
20
- attr_reader :head, :attributes, :client
20
+ attr_reader :head, :attributes, :client
21
21
 
22
- def update_item
23
- update_expression = "SET " + @attributes.map{|a| "##{a[0].upcase} = :#{a[0]}"}.join(", ")
24
- attribute_names = @attributes.map{|a| ["##{a[0].upcase}", a[0].to_s]}.to_h
25
- attribute_values = @attributes.map{|a| [":#{a[0]}", a[1]]}.to_h
22
+ def update_item
23
+ update_expression = "SET " + @attributes.map{|a| "##{a[0].upcase} = :#{a[0]}"}.join(", ")
24
+ attribute_names = @attributes.map{|a| ["##{a[0].upcase}", a[0].to_s]}.to_h
25
+ attribute_values = @attributes.map{|a| [":#{a[0]}", a[1]]}.to_h
26
26
 
27
- client.update_item(
28
- expression_attribute_names: attribute_names,
29
- expression_attribute_values: attribute_values,
30
- table_name: @head.name,
31
- key: { id: @id },
32
- return_values: "ALL_NEW",
33
- update_expression: update_expression
34
- )
35
- end
27
+ client.update_item(
28
+ expression_attribute_names: attribute_names,
29
+ expression_attribute_values: attribute_values,
30
+ table_name: @head.name,
31
+ key: { id: @id },
32
+ return_values: "ALL_NEW",
33
+ update_expression: update_expression
34
+ )
36
35
  end
37
36
  end
38
37
  end
data/lib/drop_all.rb CHANGED
@@ -1,35 +1,34 @@
1
- module Hecks
2
- module Adapters
3
- class DynamoDB
4
- class DropAll
5
- def initialize(client:, domain:)
6
- @client = client
7
- @domain = domain
8
- load(domain.spec_path)
9
- end
1
+ module HecksAdapters
2
+ class DynamoDB
3
+ # Drop all tables!
4
+ class DropAll
5
+ def initialize(client:, domain:)
6
+ @client = client
7
+ @domain = domain
8
+ load(domain.spec_path)
9
+ end
10
10
 
11
- def call
12
- list_tables
13
- drop_tables
14
- self
15
- end
11
+ def call
12
+ list_tables
13
+ drop_tables
14
+ self
15
+ end
16
16
 
17
- def result
18
- { tables: @tables }
19
- end
17
+ def result
18
+ { tables: @tables }
19
+ end
20
20
 
21
- private
21
+ private
22
22
 
23
- attr_reader :tables, :client
23
+ attr_reader :tables, :client
24
24
 
25
- def list_tables
26
- @tables = client.list_tables.table_names
27
- end
25
+ def list_tables
26
+ @tables = client.list_tables.table_names
27
+ end
28
28
 
29
- def drop_tables
30
- @tables.each do |table|
31
- client.delete_table({table_name: table})
32
- end
29
+ def drop_tables
30
+ @tables.each do |table|
31
+ client.delete_table({table_name: table})
33
32
  end
34
33
  end
35
34
  end
@@ -5,16 +5,21 @@ require_relative 'drop_all'
5
5
  require 'aws-sdk'
6
6
  require 'yaml'
7
7
 
8
- module Hecks
9
- module Adapters
10
- class DynamoDB
11
- def initialize(domain:)
12
- @domain = domain
13
- end
8
+ module HecksAdapters
9
+ # Hecks Repository interface
10
+ class DynamoDB
11
+ def initialize(domain:)
12
+ @domain = domain
13
+ end
14
14
 
15
- def [](value)
16
- Repository.new(DOMAIN[value.to_s.titleize.to_sym].head)
17
- end
15
+ # Look up a domain module
16
+ # hecks_app[:pizzas]
17
+ #
18
+ # Returns a domain module
19
+ #
20
+ # eg: PizzaBuilder::Pizzas
21
+ def [](value)
22
+ Repository.new(DOMAIN[value.to_s.titleize.to_sym].head)
18
23
  end
19
24
  end
20
25
  end
data/lib/migrate.rb CHANGED
@@ -1,52 +1,51 @@
1
- module Hecks
2
- module Adapters
3
- class DynamoDB
4
- class Migrate
5
- def initialize(client:, domain:)
6
- @client = client
7
- @unchanged_tables = []
8
- @new_tables = []
9
- @domain = domain
10
- load(@domain.spec_path)
11
- end
1
+ module HecksAdapters
2
+ class DynamoDB
3
+ # Creates tables according to your domain spec
4
+ class Migrate
5
+ def initialize(client:, domain:)
6
+ @client = client
7
+ @unchanged_tables = []
8
+ @new_tables = []
9
+ @domain = domain
10
+ load(@domain.spec_path)
11
+ end
12
12
 
13
- def call
14
- create_tables
15
- self
16
- end
13
+ def call
14
+ create_tables
15
+ self
16
+ end
17
17
 
18
- def result
19
- { unchanged_tables: @unchanged_tables, new_tables: @new_tables }
20
- end
18
+ def result
19
+ { unchanged_tables: @unchanged_tables, new_tables: @new_tables }
20
+ end
21
21
 
22
- private
22
+ private
23
23
 
24
- attr_reader :client
24
+ attr_reader :client
25
25
 
26
- def create_tables
27
- DOMAIN.domain_modules.values.each do |domain_module|
28
- create_table(domain_module.head.name)
29
- end
26
+ def create_tables
27
+ DOMAIN.domain_modules.values.each do |domain_module|
28
+ create_table(domain_module.head.name)
30
29
  end
30
+ end
31
31
 
32
- def create_table(name)
33
- begin
34
- client.create_table(
35
- attribute_definitions: [{
36
- attribute_name: 'id',
37
- attribute_type: 'S'
38
- }],
39
- table_name: name,
40
- key_schema: [{ attribute_name: 'id', key_type: 'HASH' }],
41
- provisioned_throughput: {
42
- read_capacity_units: 5,
43
- write_capacity_units: 5
44
- }
45
- )
46
- @new_tables << name
47
- rescue Aws::DynamoDB::Errors::ResourceInUseException => e
48
- @unchanged_tables << name
49
- end
32
+ def create_table(name)
33
+ begin
34
+ client.create_table(
35
+ attribute_definitions: [{
36
+ attribute_name: 'id',
37
+ attribute_type: 'S'
38
+ }],
39
+ table_name: name,
40
+ key_schema: [{ attribute_name: 'id', key_type: 'HASH' }],
41
+ provisioned_throughput: {
42
+ read_capacity_units: 5,
43
+ write_capacity_units: 5
44
+ }
45
+ )
46
+ @new_tables << name
47
+ rescue Aws::DynamoDB::Errors::ResourceInUseException => e
48
+ @unchanged_tables << name
50
49
  end
51
50
  end
52
51
  end
data/lib/repository.rb CHANGED
@@ -3,37 +3,36 @@ require_relative 'commands/read'
3
3
  require_relative 'commands/update'
4
4
  require_relative 'commands/delete'
5
5
 
6
- module Hecks
7
- module Adapters
8
- class DynamoDB
9
- class Repository
10
- attr_reader :id
11
-
12
- def initialize(head)
13
- @head = head
14
- @client = Aws::DynamoDB::Client.new(region: 'us-east-1')
15
- end
6
+ module HecksAdapters
7
+ class DynamoDB
8
+ # Use the Aws::DynamoDB::Client to persist your domain resources
9
+ class Repository
10
+ attr_reader :id
11
+
12
+ def initialize(head)
13
+ @head = head
14
+ @client = Aws::DynamoDB::Client.new(region: 'us-east-1')
15
+ end
16
16
 
17
- def create(args)
18
- Commands::Create.new(args, head, client).call
19
- end
17
+ def create(args)
18
+ Commands::Create.new(args, head, client).call
19
+ end
20
20
 
21
- def delete(id)
22
- Commands::Delete.new(id, head, client).call
23
- end
21
+ def delete(id)
22
+ Commands::Delete.new({id: id}, head, client).call
23
+ end
24
24
 
25
- def read(id)
26
- Commands::Read.new(id, head, client).call
27
- end
25
+ def read(id)
26
+ Commands::Read.new(id, head, client).call
27
+ end
28
28
 
29
- def update(id, attributes)
30
- Commands::Update.new(id, attributes, head, client).call
31
- end
29
+ def update(id, attributes)
30
+ Commands::Update.new(id, attributes, head, client).call
31
+ end
32
32
 
33
- private
33
+ private
34
34
 
35
- attr_reader :head, :client
36
- end
35
+ attr_reader :head, :client
37
36
  end
38
37
  end
39
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hecks-adapters-dynamodb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Young
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-15 00:00:00.000000000 Z
11
+ date: 2017-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -61,5 +61,5 @@ rubyforge_project:
61
61
  rubygems_version: 2.6.10
62
62
  signing_key:
63
63
  specification_version: 4
64
- summary: Drive DynamoDB with Domains created with Hecks::Domain
64
+ summary: Drive DynamoDB with Domains created with HecksDomain
65
65
  test_files: []