dynamo-local-ruby 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rubocop.yml +7 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +7 -0
- data/dynamo-local-ruby.gemspec +26 -0
- data/lib/dynamo-local-ruby.rb +5 -0
- data/lib/dynamo-local-ruby/dynamo_db_local.rb +49 -0
- data/lib/dynamo-local-ruby/schema_loader.rb +53 -0
- data/lib/dynamo-local-ruby/version.rb +6 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d88cfeb4d699b0b86c215120b9271c36bdea10eb
|
4
|
+
data.tar.gz: 7c90f7cf23759d34b451d5f0b3b09cdf559f8e60
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad4e37aa7c504f170b0f48b4031a045fd811d61e8250d66e5d2f7afa48a741e39485dcbac8c17e066a3653cb470c4185bd21543c368e78dfdf2652a8fc7374c8
|
7
|
+
data.tar.gz: 5d3650733ef2f4b1e81d636e8dc56adbb7e3722854322021e5b8f5c4aba11279968daa093b05600c815ddf578538166f2a541e47a36ec026c5ab0b47b7415616
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Peak Xu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# DynamoLocalRuby
|
2
|
+
|
3
|
+
Ruby wrapper around DynamoLocal to enable easier testing of your Ruby code that uses Dynamo.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'dynamo-local-ruby'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install dynamo-local-ruby
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In your application code, initialize Dynamo clients with
|
24
|
+
|
25
|
+
Aws::DynamoDB::Client.new(endpoint: DynamoLocalRuby::DynamoDBLocal::ENDPOINT)
|
26
|
+
|
27
|
+
Before the test suite starts (for instance in RSpec's `config.before(:suite)`). Where `<build directory>` is accessible path in your project's path for build process artifacts.
|
28
|
+
|
29
|
+
DynamoLocalRuby::DynamoDBLocal.up(<build_directory>)
|
30
|
+
|
31
|
+
When cleaning up test suite (for instance in RSpec's `config.after(:suite)`)
|
32
|
+
|
33
|
+
DynamoLocalRuby::DynamoDBLocal.down
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it ( https://github.com/[my-github-username]/dynamo-local-ruby/fork )
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dynamo-local-ruby'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dynamo-local-ruby'
|
8
|
+
spec.version = DynamoLocalRuby::VERSION
|
9
|
+
spec.authors = ['Peak Xu']
|
10
|
+
spec.email = ['peak.xu@gmail.com']
|
11
|
+
spec.summary = 'Ruby wrapper around DynamoDB Local for use with AWS-SDK'
|
12
|
+
spec.description = 'Ruby wrapper around DynamoDB Local for use with AWS-SDK'
|
13
|
+
spec.homepage = 'https://github.com/peakxu/dynamo-local-ruby'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(/^bin/) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)/)
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'aws-sdk', '~> 2.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rubocop'
|
26
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Start dynamo DB local
|
3
|
+
module DynamoLocalRuby
|
4
|
+
# Wrapper around Dynamo DB local process
|
5
|
+
class DynamoDBLocal
|
6
|
+
PORT = 9389
|
7
|
+
ENDPOINT = "http://localhost:#{PORT}"
|
8
|
+
LATEST_WEB_TGZ = 'http://dynamodb-local.s3-website-us-west-2.amazonaws.com'\
|
9
|
+
'/dynamodb_local_latest.tar.gz'
|
10
|
+
|
11
|
+
def initialize(pid)
|
12
|
+
@pid = pid
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def ensure_dynamo_local_exists(local_path)
|
17
|
+
jar_path = File.join(local_path, 'DynamoDBLocal.jar')
|
18
|
+
return if File.exist?(jar_path)
|
19
|
+
`mkdir -p #{local_path}`
|
20
|
+
latest = File.join(local_path, 'dynamodb_local_latest.tar.gz')
|
21
|
+
`wget #{LATEST_WEB_TGZ} -o #{latest}` unless File.exist?(latest)
|
22
|
+
`tar xzf #{latest} -C #{local_path}`
|
23
|
+
end
|
24
|
+
|
25
|
+
def up(build_path)
|
26
|
+
local_path = File.join(build_path, 'dynamo_db_local')
|
27
|
+
ensure_dynamo_local_exists(local_path)
|
28
|
+
lib_path = File.join(local_path, 'DynamoDBLocal_lib')
|
29
|
+
jar_path = File.join(local_path, 'DynamoDBLocal.jar')
|
30
|
+
pid = spawn("java -Djava.library.path=#{lib_path} -jar #{jar_path} "\
|
31
|
+
"-sharedDb -inMemory -port #{PORT}")
|
32
|
+
@instance = DynamoDBLocal.new(pid)
|
33
|
+
|
34
|
+
@instance
|
35
|
+
end
|
36
|
+
|
37
|
+
def down
|
38
|
+
@instance.down if defined? @instance
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def down
|
43
|
+
return unless @pid
|
44
|
+
Process.kill('SIGINT', @pid)
|
45
|
+
Process.waitpid2(@pid)
|
46
|
+
@pid = nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'aws-sdk'
|
3
|
+
|
4
|
+
# Start dynamo DB local
|
5
|
+
module DynamoLocalRuby
|
6
|
+
# Helper for creating tables from a schema definition
|
7
|
+
class SchemaLoader
|
8
|
+
def initialize(dynamo_client)
|
9
|
+
@dynamo = Aws::DynamoDB::Resource.new(client: dynamo_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Expect schema to have form
|
13
|
+
# {
|
14
|
+
# 'table_name' => {
|
15
|
+
# keys: {
|
16
|
+
# 'foo' => { attribute_type: 'S', key_type: 'HASH' }
|
17
|
+
# },
|
18
|
+
# capacity: { read: 1, write: 1 } # optional
|
19
|
+
# }
|
20
|
+
# }
|
21
|
+
def load(schema)
|
22
|
+
schema.each { |name, table_schema| load_table(name, table_schema) }
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def load_table(name, schema)
|
28
|
+
@dynamo.table(name).table_status
|
29
|
+
rescue Aws::DynamoDB::Errors::ResourceNotFoundException
|
30
|
+
opts = { table_name: name, attribute_definitions: [],
|
31
|
+
key_schema: [], provisioned_throughput: {} }
|
32
|
+
load_keys_to_opts(opts, schema)
|
33
|
+
load_capacity_to_opts(opts, schema)
|
34
|
+
@dynamo.create_table(opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
def load_keys_to_opts(opts, schema)
|
38
|
+
schema[:keys].each do |key, payload|
|
39
|
+
opts[:attribute_definitions] << {
|
40
|
+
attribute_name: key.to_s, attribute_type: payload[:attribute_type] }
|
41
|
+
opts[:key_schema] << {
|
42
|
+
attribute_name: key.to_s, key_type: payload[:key_type] }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def load_capacity_to_opts(opts, schema)
|
47
|
+
read = schema[:capacity] ? schema[:capacity][:read] : 1
|
48
|
+
write = schema[:capacity] ? schema[:capacity][:write] : 1
|
49
|
+
opts[:provisioned_throughput] = {
|
50
|
+
read_capacity_units: read, write_capacity_units: write }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dynamo-local-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peak Xu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Ruby wrapper around DynamoDB Local for use with AWS-SDK
|
70
|
+
email:
|
71
|
+
- peak.xu@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- dynamo-local-ruby.gemspec
|
83
|
+
- lib/dynamo-local-ruby.rb
|
84
|
+
- lib/dynamo-local-ruby/dynamo_db_local.rb
|
85
|
+
- lib/dynamo-local-ruby/schema_loader.rb
|
86
|
+
- lib/dynamo-local-ruby/version.rb
|
87
|
+
homepage: https://github.com/peakxu/dynamo-local-ruby
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Ruby wrapper around DynamoDB Local for use with AWS-SDK
|
111
|
+
test_files: []
|