dynamodb-ruby 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f400f961c27724abdf925b662694594bf00255d
4
- data.tar.gz: 71afe2c4f0b094132cf51c4079c1b2ac71052157
3
+ metadata.gz: 9b99cc1d64a32fc529e155f1dc3ebf5367f36d13
4
+ data.tar.gz: 1c435fa098709a27bee35d7eda5c5d12ce1d2afa
5
5
  SHA512:
6
- metadata.gz: 1e788f4edf4e7da658eafa93b01a92794c2db47ba02351214c9a2b5c2093ed91d47e38b53db55c7438ea975624e4392236e5dbe17bbe7a46121c651bef2bafc7
7
- data.tar.gz: 705d36d92187787ff5e01c65344f8b84f78f601ba8ce14efbe771848cdcaa6b5988ee51801c1c44fb5dd9516741f84138f07ea43cfb80ab4ee0596f1cd01ee7d
6
+ metadata.gz: 42a4cc5f59362040562152601450dfde6ce465e3a0977ee97b729d8a5ecabcd8deaebdc997e928857c4fd37d4053dd6f7cffdbd6ed8acfee66c7a2b07c7ef354
7
+ data.tar.gz: ee33d3746e1bb0644014efbcda93a1d2e4e8bd3ff8870f23df7c61af8568dab9324472a244b70df526a293ec71dc695ddc3b9cc4b886c85cbeda32631b725ce3
@@ -1,10 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dynamodb/version"
4
+ require "dynamodb/configuration"
4
5
  require "dynamodb/connection"
5
6
  require "dynamodb/table_actions"
6
7
 
7
8
  module Dynamodb
8
9
  extend Connection
9
10
  extend TableActions
11
+
12
+ class << self
13
+ attr_accessor :configuration
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def self.reset
21
+ @configuration = Configuration.new
22
+ end
23
+
24
+ def self.configure
25
+ yield(configuration)
26
+ end
10
27
  end
@@ -0,0 +1,11 @@
1
+ module Dynamodb
2
+ class Configuration
3
+ attr_accessor :client_config, :can_create_tables, :can_delete_tables
4
+
5
+ def initialize
6
+ @client_config = { stub_responses: true }
7
+ @can_create_tables = false
8
+ @can_delete_tables = false
9
+ end
10
+ end
11
+ end
@@ -4,33 +4,21 @@ require "aws-sdk-dynamodb"
4
4
 
5
5
  module Dynamodb
6
6
  module Connection
7
- def client
8
- @@client ||= Aws::DynamoDB::Client.new(config)
9
- end
7
+ def client(new_connection = nil)
8
+ return (@@client = new_connection) unless new_connection.nil?
10
9
 
11
- def client=(new_connection)
12
- @@client = new_connection
10
+ @@client ||= Aws::DynamoDB::Client.new(Dynamodb.configuration.client_config)
13
11
  end
14
12
 
15
- def reset_client
16
- @@client = nil
17
- @@resource = nil
18
- end
13
+ def resource(new_resource = nil)
14
+ return (@@resource = new_resource) unless new_resource.nil?
19
15
 
20
- def resource
21
16
  @@resource ||= Aws::DynamoDB::Resource.new(client: client)
22
17
  end
23
18
 
24
- def resource=(new_resource)
25
- @@resource = new_resource
26
- end
27
-
28
- def config
29
- @@config ||= { }
30
- end
31
-
32
- def config=(client_config)
33
- @@config = client_config
19
+ def reset_client
20
+ @@client = nil
21
+ @@resource = nil
34
22
  end
35
23
  end
36
24
  end
@@ -10,15 +10,8 @@ module Dynamodb
10
10
  class << self
11
11
  attr_reader :dynamodb
12
12
 
13
- def init_dynamodb
14
- @dynamodb ||= Dynamodb
15
- # Note: Set database to point to dynamodb local
16
- @dynamodb.config = { endpoint: "http://localhost:10070" }
17
- @dynamodb.reset_client # reset the connection
18
- end
19
-
20
13
  def reset
21
- init_dynamodb
14
+ @dynamodb ||= Dynamodb
22
15
 
23
16
  teardown
24
17
  build_tables # DynamoDBSchema#build_tables
@@ -46,10 +46,16 @@ module Dynamodb
46
46
  end
47
47
 
48
48
  def delete_table(_table_name)
49
+ # To prevent accidentally deleting tables in production
50
+ raise 'Can not delete tables' unless Dynamodb.configuration.can_delete_tables
51
+
49
52
  client.delete_table(table_name: _table_name)
50
53
  end
51
54
 
52
55
  def create_table(_table_name, options)
56
+ # To prevent accidentally deleting tables in production
57
+ raise 'Can not create tables' unless Dynamodb.configuration.can_create_tables
58
+
53
59
  resource.create_table(
54
60
  {
55
61
  table_name: _table_name,
@@ -1,3 +1,3 @@
1
1
  module Dynamodb
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamodb-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Farrow
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-09 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -117,6 +117,7 @@ files:
117
117
  - lib/dynamodb.rb
118
118
  - lib/dynamodb/attribute_assignment.rb
119
119
  - lib/dynamodb/base.rb
120
+ - lib/dynamodb/configuration.rb
120
121
  - lib/dynamodb/connection.rb
121
122
  - lib/dynamodb/local.rb
122
123
  - lib/dynamodb/querying.rb