toy-dynamo 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/toy/dynamo/adapter.rb +0 -2
- data/lib/toy/dynamo/config.rb +0 -1
- data/lib/toy/dynamo/tasks.rb +32 -2
- data/lib/toy/dynamo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55543749d5aada53a2339255fecf85562746b958
|
4
|
+
data.tar.gz: ae3a9255c0d8d90187c4de0651ea3e262cf9c807
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82d0ac9c53c7ec511df84d4afe592c946bf8567c5c1dce86c913b667937b033f9f408b71275c895a3a1889a03a1de7ecfc42ffea5345e2b006579c5a9e0c551f
|
7
|
+
data.tar.gz: 8e08548bbc6a408cc179d2f2c358e16f7b10eeef69aaf772ff14b1117a483a5d8f2fec85d26bf26a8a3efdd4595ffc89854f367255d35a0fb5ffe61eaece5983
|
data/lib/toy/dynamo/adapter.rb
CHANGED
@@ -11,8 +11,6 @@ module Toy
|
|
11
11
|
options[:dynamo_db_endpoint] = config[:endpoint] || Toy::Dynamo::Config.endpoint
|
12
12
|
options[:dynamo_db_port] = config[:port] || Toy::Dynamo::Config.port
|
13
13
|
|
14
|
-
options[:dynamo_db_endpoint] = config[:endpoint] || Toy::Dynamo::Config.endpoint
|
15
|
-
options[:dynamo_db_port] = config[:port] || Toy::Dynamo::Config.port
|
16
14
|
options[:api_version] ||= config[:api_version] || '2012-08-10'
|
17
15
|
#:dynamo_db_crc_32_check = false
|
18
16
|
|
data/lib/toy/dynamo/config.rb
CHANGED
@@ -15,7 +15,6 @@ module Toy
|
|
15
15
|
option :logger, :default => defined?(Rails)
|
16
16
|
option :read_provision, :default => 50
|
17
17
|
option :write_provision, :default => 10
|
18
|
-
option :included_models, :default => []
|
19
18
|
# TODO - default adapter client based on config
|
20
19
|
#option :namespace, :default => defined?(Rails) ? "#{Rails.application.class.parent_name}_#{Rails.env}" : ""
|
21
20
|
option :endpoint, :default => 'dynamodb.us-west-2.amazonaws.com'
|
data/lib/toy/dynamo/tasks.rb
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
require 'rake'
|
2
2
|
|
3
|
+
module Toy
|
4
|
+
module Dynamo
|
5
|
+
module Tasks
|
6
|
+
extend self
|
7
|
+
def included_models
|
8
|
+
dir = ENV['DIR'].to_s != '' ? ENV['DIR'] : Rails.root.join("app/models")
|
9
|
+
puts "Loading models from: #{dir}"
|
10
|
+
included = []
|
11
|
+
Dir.glob(File.join("#{dir}/**/*.rb")).each do |path|
|
12
|
+
model_filename = path[/#{Regexp.escape(dir.to_s)}\/([^\.]+).rb/, 1]
|
13
|
+
next if model_filename.match(/^concerns\//i) # Skip concerns/ folder
|
14
|
+
klass = model_filename.camelize.constantize
|
15
|
+
|
16
|
+
begin
|
17
|
+
klass = model_filename.camelize.constantize
|
18
|
+
rescue NameError
|
19
|
+
require(path) ? retry : raise
|
20
|
+
end
|
21
|
+
|
22
|
+
# Skip if the class doesn't have Toy::Dynamo integration
|
23
|
+
next unless klass.respond_to?(:dynamo_table)
|
24
|
+
|
25
|
+
included << klass
|
26
|
+
end
|
27
|
+
included
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
3
33
|
namespace :ddb do
|
4
34
|
desc 'Create a DynamoDB table'
|
5
35
|
task :create => :environment do
|
@@ -7,7 +37,7 @@ namespace :ddb do
|
|
7
37
|
options = {}
|
8
38
|
options.merge!(:table_name => ENV['TABLE']) if ENV['TABLE']
|
9
39
|
if ENV["CLASS"] == "all"
|
10
|
-
Toy::Dynamo::
|
40
|
+
Toy::Dynamo::Tasks.included_models.each do |klass|
|
11
41
|
puts "Creating table for #{klass}..."
|
12
42
|
begin
|
13
43
|
klass.dynamo_table(:novalidate => true).create(options)
|
@@ -36,7 +66,7 @@ namespace :ddb do
|
|
36
66
|
options = {}
|
37
67
|
options.merge!(:table_name => ENV['TABLE']) if ENV['TABLE']
|
38
68
|
if ENV["CLASS"] == "all"
|
39
|
-
Toy::Dynamo::
|
69
|
+
Toy::Dynamo::Tasks.included_models.each do |klass|
|
40
70
|
puts "Destroying table for #{klass}..."
|
41
71
|
begin
|
42
72
|
klass.dynamo_table(:novalidate => true).delete(options)
|
data/lib/toy/dynamo/version.rb
CHANGED