dynamodb-ruby 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dynamodb.rb +17 -0
- data/lib/dynamodb/configuration.rb +11 -0
- data/lib/dynamodb/connection.rb +8 -20
- data/lib/dynamodb/local.rb +1 -8
- data/lib/dynamodb/table_actions.rb +6 -0
- data/lib/dynamodb/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b99cc1d64a32fc529e155f1dc3ebf5367f36d13
|
4
|
+
data.tar.gz: 1c435fa098709a27bee35d7eda5c5d12ce1d2afa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42a4cc5f59362040562152601450dfde6ce465e3a0977ee97b729d8a5ecabcd8deaebdc997e928857c4fd37d4053dd6f7cffdbd6ed8acfee66c7a2b07c7ef354
|
7
|
+
data.tar.gz: ee33d3746e1bb0644014efbcda93a1d2e4e8bd3ff8870f23df7c61af8568dab9324472a244b70df526a293ec71dc695ddc3b9cc4b886c85cbeda32631b725ce3
|
data/lib/dynamodb.rb
CHANGED
@@ -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
|
data/lib/dynamodb/connection.rb
CHANGED
@@ -4,33 +4,21 @@ require "aws-sdk-dynamodb"
|
|
4
4
|
|
5
5
|
module Dynamodb
|
6
6
|
module Connection
|
7
|
-
def client
|
8
|
-
@@client
|
9
|
-
end
|
7
|
+
def client(new_connection = nil)
|
8
|
+
return (@@client = new_connection) unless new_connection.nil?
|
10
9
|
|
11
|
-
|
12
|
-
@@client = new_connection
|
10
|
+
@@client ||= Aws::DynamoDB::Client.new(Dynamodb.configuration.client_config)
|
13
11
|
end
|
14
12
|
|
15
|
-
def
|
16
|
-
@@
|
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
|
25
|
-
@@
|
26
|
-
|
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
|
data/lib/dynamodb/local.rb
CHANGED
@@ -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
|
-
|
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,
|
data/lib/dynamodb/version.rb
CHANGED
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.
|
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-
|
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
|