dynamodb_model 1.0.3 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebb8c152e61da170579ab144ccd846db12c32183
4
- data.tar.gz: 6a730d72947f0226cf2a5584876f26f9fee6c9cb
3
+ metadata.gz: eaf77d31c24af901f7763c0c1ef41a9826fa7a39
4
+ data.tar.gz: a8d44492a552c139905c932d99235ccb9fdadc28
5
5
  SHA512:
6
- metadata.gz: 859d701784e3a04af34f8757cd7f827fd811a4c41332526a546d7823609ae2f91f97f414dae8742a354ef63d4b3a5b5a8789ce60e8ad5cc92f9d90de3c100149
7
- data.tar.gz: 7c59f80c2167cde76f604b420f1fd2d584be8373de065e2cb7218bb1ec30861b689346a3ccc535b91f96b6a16d7440172a973481959f0c5b7cf7b2d460ed72b4
6
+ metadata.gz: 3246ab2a294b39d83bd33f9dede7d69fb786f039c647310c3c8a0b27e0a35531f0cb0686c0b7befcd8c81fe2f5e016d4e0560dbfde6493af5d93b9cb92e75f13
7
+ data.tar.gz: ed45418a301d6e72d040bd5d9cdbcd9b8f3cfb7fee09d93d37fcfa42af44befe38d4ffe3fbacee621f91f3c63723117d20f3f054137177444269fd7f760361d6
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.0.5]
7
+ - fix jets dynamodb:migrate tip
8
+
9
+ ## [1.0.4]
10
+ - Add and use log method instead of puts to write to stderr by default
11
+
6
12
  ## [1.0.3]
7
13
  - rename APP_ROOT to JETS_ROOT
8
14
 
@@ -15,8 +15,9 @@ module DynamodbModel
15
15
  autoload :Dsl, "dynamodb_model/dsl"
16
16
  autoload :DbConfig, "dynamodb_model/db_config"
17
17
  autoload :Item, "dynamodb_model/item"
18
- autoload :Util, "dynamodb_model/util"
18
+ autoload :Core, "dynamodb_model/core"
19
19
  autoload :Erb, "dynamodb_model/erb"
20
+ autoload :Log, "dynamodb_model/log"
20
21
 
21
- extend Util
22
+ extend Core
22
23
  end
@@ -1,15 +1,25 @@
1
1
  require 'logger'
2
2
 
3
- module DynamodbModel::Util
3
+ module DynamodbModel::Core
4
4
  # Ensures trailing slash
5
5
  # Useful for appending a './' in front of a path or leaving it alone.
6
6
  # Returns: '/path/with/trailing/slash/' or './'
7
7
  @@app_root = nil
8
8
  def app_root
9
9
  return @@app_root if @@app_root
10
- @@app_root = ENV['JETS_ROOT'].to_s
11
- @@app_root = '.' if @@app_root == ''
10
+ @@app_root = ENV['APP_ROOT'] || ENV['JETS_ROOT'] || ENV['RAILS_ROOT']
11
+ @@app_root = '.' if @@app_root.nil? || @app_root == ''
12
12
  @@app_root = "#{@@app_root}/" unless @@app_root.ends_with?('/')
13
13
  @@app_root
14
14
  end
15
+
16
+ @@logger = nil
17
+ def logger
18
+ return @@logger if @@logger
19
+ @@logger = Logger.new($stderr)
20
+ end
21
+
22
+ def logger=(value)
23
+ @@logger = value
24
+ end
15
25
  end
@@ -74,7 +74,7 @@ module DynamodbModel::DbConfig
74
74
  env = ENV['DYNAMODB_MODEL_ENV'] || "development"
75
75
  end
76
76
 
77
- config = YAML.load(erb_result(config_path))
77
+ config = YAML.load(DynamodbModel::Erb.result(config_path))
78
78
  @db_config ||= config[env] || {}
79
79
  end
80
80
 
@@ -97,38 +97,5 @@ module DynamodbModel::DbConfig
97
97
  def set_table_namespace(value)
98
98
  @table_namespace = value
99
99
  end
100
-
101
- def erb_result(path)
102
- template = IO.read(path)
103
- begin
104
- ERB.new(template, nil, "-").result(binding)
105
- rescue Exception => e
106
- puts e
107
- puts e.backtrace if ENV['DEBUG']
108
-
109
- # how to know where ERB stopped? - https://www.ruby-forum.com/topic/182051
110
- # syntax errors have the (erb):xxx info in e.message
111
- # undefined variables have (erb):xxx info in e.backtrac
112
- error_info = e.message.split("\n").grep(/\(erb\)/)[0]
113
- error_info ||= e.backtrace.grep(/\(erb\)/)[0]
114
- raise unless error_info # unable to find the (erb):xxx: error line
115
- line = error_info.split(':')[1].to_i
116
- puts "Error evaluating ERB template on line #{line.to_s.colorize(:red)} of: #{path.sub(/^\.\//, '').colorize(:green)}"
117
-
118
- template_lines = template.split("\n")
119
- context = 5 # lines of context
120
- top, bottom = [line-context-1, 0].max, line+context-1
121
- spacing = template_lines.size.to_s.size
122
- template_lines[top..bottom].each_with_index do |line_content, index|
123
- line_number = top+index+1
124
- if line_number == line
125
- printf("%#{spacing}d %s\n".colorize(:red), line_number, line_content)
126
- else
127
- printf("%#{spacing}d %s\n", line_number, line_content)
128
- end
129
- end
130
- exit 1 unless ENV['TEST']
131
- end
132
- end
133
100
  end
134
101
  end
@@ -7,6 +7,8 @@ require 'erb'
7
7
  # result = DynamodbModel::Erb.result(path, key1: "val1", key2: "val2")
8
8
  #
9
9
  class DynamodbModel::Erb
10
+ include DynamodbModel::Log
11
+
10
12
  class << self
11
13
  def result(path, variables={})
12
14
  set_template_variables(variables)
@@ -14,8 +16,8 @@ class DynamodbModel::Erb
14
16
  begin
15
17
  ERB.new(template, nil, "-").result(binding)
16
18
  rescue Exception => e
17
- puts e
18
- puts e.backtrace if ENV['DEBUG']
19
+ log(e)
20
+ log(e.backtrace) if ENV['DEBUG']
19
21
 
20
22
  # how to know where ERB stopped? - https://www.ruby-forum.com/topic/182051
21
23
  # syntax errors have the (erb):xxx info in e.message
@@ -24,7 +26,7 @@ class DynamodbModel::Erb
24
26
  error_info ||= e.backtrace.grep(/\(erb\)/)[0]
25
27
  raise unless error_info # unable to find the (erb):xxx: error line
26
28
  line = error_info.split(':')[1].to_i
27
- puts "Error evaluating ERB template on line #{line.to_s.colorize(:red)} of: #{path.sub(/^\.\//, '').colorize(:green)}"
29
+ log "Error evaluating ERB template on line #{line.to_s.colorize(:red)} of: #{path.sub(/^\.\//, '').colorize(:green)}"
28
30
 
29
31
  template_lines = template.split("\n")
30
32
  context = 5 # lines of context
@@ -37,6 +37,7 @@ require "yaml"
37
37
  #
38
38
  module DynamodbModel
39
39
  class Item
40
+ include Log
40
41
  include DbConfig
41
42
 
42
43
  def initialize(attrs={})
@@ -121,7 +122,7 @@ module DynamodbModel
121
122
  #
122
123
  # AWS Docs examples: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.Ruby.04.html
123
124
  def self.scan(params={})
124
- puts("It's recommended to not use scan for production. It can be slow and expensive. You can a LSI or GSI and query the index instead.")
125
+ log("It's recommended to not use scan for production. It can be slow and expensive. You can a LSI or GSI and query the index instead.")
125
126
  params = { table_name: table_name }.merge(params)
126
127
  resp = db.scan(params)
127
128
  resp.items.map {|i| self.new(i) }
@@ -0,0 +1,15 @@
1
+ module DynamodbModel::Log
2
+ def self.included(base)
3
+ base.extend(ClassMethods)
4
+ end
5
+
6
+ def log(msg)
7
+ self.class.log(msg)
8
+ end
9
+
10
+ module ClassMethods
11
+ def log(msg)
12
+ DynamodbModel.logger.info(msg)
13
+ end
14
+ end
15
+ end
@@ -1,7 +1,7 @@
1
1
  require "active_support/core_ext/string"
2
2
 
3
3
  class DynamodbModel::Migration
4
- # jets dynamodb generate posts --partition-key id:string
4
+ # jets dynamodb:generate posts --partition-key id:string
5
5
  class Generator
6
6
  include DynamodbModel::DbConfig
7
7
 
@@ -21,7 +21,7 @@ class DynamodbModel::Migration
21
21
  FileUtils.mkdir_p(File.dirname(migration_path))
22
22
  IO.write(migration_path, migration_code)
23
23
  puts "Migration file created: #{migration_path}. \nTo run:"
24
- puts " jets dynamodb migrate #{migration_path}"
24
+ puts " jets dynamodb:migrate #{migration_path}"
25
25
  end
26
26
 
27
27
  def migration_code
@@ -1,3 +1,3 @@
1
1
  module DynamodbModel
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamodb_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-24 00:00:00.000000000 Z
11
+ date: 2017-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -99,9 +99,11 @@ files:
99
99
  - docs/migrations/short-example.rb
100
100
  - dynamodb_model.gemspec
101
101
  - lib/dynamodb_model.rb
102
+ - lib/dynamodb_model/core.rb
102
103
  - lib/dynamodb_model/db_config.rb
103
104
  - lib/dynamodb_model/erb.rb
104
105
  - lib/dynamodb_model/item.rb
106
+ - lib/dynamodb_model/log.rb
105
107
  - lib/dynamodb_model/migration.rb
106
108
  - lib/dynamodb_model/migration/common.rb
107
109
  - lib/dynamodb_model/migration/dsl.rb
@@ -112,7 +114,6 @@ files:
112
114
  - lib/dynamodb_model/migration/generator.rb
113
115
  - lib/dynamodb_model/migration/templates/create_table.rb
114
116
  - lib/dynamodb_model/migration/templates/update_table.rb
115
- - lib/dynamodb_model/util.rb
116
117
  - lib/dynamodb_model/version.rb
117
118
  homepage: https://github.com/tongueroo/dynamodb_model
118
119
  licenses: []