toy-dynamo 0.1.2 → 0.1.3

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: b009000e9ef292d89e89f980ff8696d92990f861
4
- data.tar.gz: 29e1c1455056be654a8757834493f45c906e3ce6
3
+ metadata.gz: 55543749d5aada53a2339255fecf85562746b958
4
+ data.tar.gz: ae3a9255c0d8d90187c4de0651ea3e262cf9c807
5
5
  SHA512:
6
- metadata.gz: 5fcef06c3655d1ad8d845616ed95b1a00d813705dd268255eb3b3109e5912fa78fc57ac715db5f505e9e9a5aa4b7be7f094acf067b9f7a3c0a01e6b37f3d1a0f
7
- data.tar.gz: 768bef23ff4fb4cbf4298c1c9070f47ea437ff0347ddbcad253c95938c24c53e7d4c4bfa45750a9be3c21a7bca53da1ed4fac0b3af8fe879f461edce69878698
6
+ metadata.gz: 82d0ac9c53c7ec511df84d4afe592c946bf8567c5c1dce86c913b667937b033f9f408b71275c895a3a1889a03a1de7ecfc42ffea5345e2b006579c5a9e0c551f
7
+ data.tar.gz: 8e08548bbc6a408cc179d2f2c358e16f7b10eeef69aaf772ff14b1117a483a5d8f2fec85d26bf26a8a3efdd4595ffc89854f367255d35a0fb5ffe61eaece5983
@@ -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
 
@@ -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'
@@ -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::Config.included_models.each do |klass|
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::Config.included_models.each do |klass|
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)
@@ -1,5 +1,5 @@
1
1
  module Toy
2
2
  module Dynamo
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toy-dynamo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cary Dunn