dynamoid-edge 1.1.1 → 1.1.2

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: 80ef1eaf479540803590814d5cf4d531faa12cf2
4
- data.tar.gz: 901734ae300344fd6294f83818781216ad3f3425
3
+ metadata.gz: 89f5ec8ebc0125c13db45a373225d0f0e48b7b36
4
+ data.tar.gz: d8432cb896ea0dde8df4c62a9db8ccb13238da36
5
5
  SHA512:
6
- metadata.gz: 3fde56e03afd236911cd55022d3581dc9974248cf2b4b5656bef9fb9de32c631fd9962bbad637da971b52c54531aec3f028e7c34541a29ff7df862b4dad9ae51
7
- data.tar.gz: 7bfe7c2c91508f757b2018a6d9459cc5f306a0ef2d84eadfd004c534ce5c68cd763cbec842cce3055117c60deb9174604cff845ec40ccf9c46afec07fec6fde1
6
+ metadata.gz: 40b2b578f2fff4a1f61de8d415f1a4bc3d1bcd8b03e60322959988c7ab3a0f8edffbef1d2c705e5f11a734cc192bb35b21490ac5dbaef4b257605d2b4d41f2db
7
+ data.tar.gz: d593fb286cb87128ca5a55915a53e25600e29972a4a0f1d1b8c23db702f66a69c0d067f2dad36feb812c53970911b0f086699c816d0215ab67ff30dc6d2b6253
@@ -56,10 +56,10 @@ Then you need to initialize Dynamoid config to get it going. Put code similar to
56
56
  ```ruby
57
57
  Dynamoid.configure do |config|
58
58
  config.adapter = 'aws_sdk_v2' # This adapter establishes a connection to the DynamoDB servers using Amazon's own AWS gem.
59
- config.namespace = "dynamoid_app_development" # To namespace tables created by Dynamoid from other tables you might have.
59
+ config.namespace = "dynamoid_app_development" # To namespace tables created by Dynamoid from other tables you might have. Set to nil to avoid namespacing.
60
60
  config.warn_on_scan = true # Output a warning to the logger when you perform a scan rather than a query on a table.
61
- config.read_capacity = 100 # Read capacity for your tables
62
- config.write_capacity = 20 # Write capacity for your tables
61
+ config.read_capacity = 5 # Read capacity for your tables
62
+ config.write_capacity = 5 # Write capacity for your tables
63
63
  config.endpoint = 'http://localhost:3000' # [Optional]. If provided, it communicates with the DB listening at the endpoint. This is useful for testing with [Amazon Local DB] (http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tools.DynamoDBLocal.html).
64
64
  end
65
65
 
@@ -86,7 +86,7 @@ Dynamoid has some sensible defaults for you when you create a new table, includi
86
86
  class User
87
87
  include Dynamoid::Document
88
88
 
89
- table :name => :awesome_users, :key => :user_id, :read_capacity => 400, :write_capacity => 400
89
+ table :name => :awesome_users, :key => :user_id, :read_capacity => 5, :write_capacity => 5
90
90
  end
91
91
  ```
92
92
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "dynamoid-edge"
5
- s.version = "1.1.1"
5
+ s.version = "1.1.2"
6
6
 
7
7
  # Keep in sync with README
8
8
  s.authors = [
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  LICENSE.txt
29
29
  README.markdown
30
30
  Rakefile
31
- dynamoid-edge.gemspec
31
+ dynamoid.gemspec
32
32
  lib/dynamoid.rb
33
33
  lib/dynamoid/adapter.rb
34
34
  lib/dynamoid/adapter_plugin/aws_sdk_v2.rb
@@ -51,8 +51,8 @@ Gem::Specification.new do |s|
51
51
  lib/dynamoid/fields.rb
52
52
  lib/dynamoid/finders.rb
53
53
  lib/dynamoid/identity_map.rb
54
- lib/dynamoid/indexes.rb
55
54
  lib/dynamoid/middleware/identity_map.rb
55
+ lib/dynamoid/indexes.rb
56
56
  lib/dynamoid/persistence.rb
57
57
  lib/dynamoid/validations.rb
58
58
  )
@@ -73,3 +73,4 @@ Gem::Specification.new do |s|
73
73
  s.add_development_dependency(%q<pry>, [">= 0"])
74
74
  s.add_development_dependency(%q<coveralls>, [">= 0"])
75
75
  end
76
+
@@ -526,7 +526,7 @@ module Dynamoid
526
526
  }
527
527
 
528
528
  # If the projection type is include, specify the non key attributes
529
- if index.projection_type == "INCLUDE"
529
+ if index.projection_type == :include
530
530
  hash[:projection][:non_key_attributes] = index.projected_attributes
531
531
  end
532
532
 
@@ -99,6 +99,17 @@ module Dynamoid #:nodoc:
99
99
  source.send(source_attribute) || Set.new
100
100
  end
101
101
 
102
+ # Create a new instance of the target class without trying to add it to the association. This creates a base, that caller can update before setting or adding it.
103
+ #
104
+ # @param [Hash] attribute hash for the new object
105
+ #
106
+ # @return [Dynamoid::Document] the newly-created object
107
+ #
108
+ # @since 1.1.1
109
+ def build(attributes = {})
110
+ target_class.build(attributes)
111
+ end
112
+
102
113
  end
103
114
  end
104
115
 
@@ -145,8 +145,10 @@ module Dynamoid #:nodoc:
145
145
  #
146
146
  # @since 0.2.0
147
147
  def where(args)
148
- args.each {|k, v| query[k] = v}
149
- self
148
+ filtered = clone
149
+ filtered.query = query.clone
150
+ args.each {|k, v| filtered.query[k] = v}
151
+ filtered
150
152
  end
151
153
 
152
154
  # Is this array equal to the association's records?
@@ -25,7 +25,7 @@ module Dynamoid #:nodoc:
25
25
  end
26
26
 
27
27
  def create(attributes = {})
28
- setter(target_class.create!(attributes))
28
+ setter(target_class.create(attributes))
29
29
  end
30
30
 
31
31
 
@@ -152,13 +152,15 @@ module Dynamoid #:nodoc:
152
152
 
153
153
  case key.to_s.split('.').last
154
154
  when 'gt'
155
- { :range_greater_than => val.to_f }
155
+ { :range_greater_than => val }
156
156
  when 'lt'
157
- { :range_less_than => val.to_f }
157
+ { :range_less_than => val }
158
158
  when 'gte'
159
- { :range_gte => val.to_f }
159
+ { :range_gte => val }
160
160
  when 'lte'
161
- { :range_lte => val.to_f }
161
+ { :range_lte => val }
162
+ when 'between'
163
+ { :range_between => val }
162
164
  when 'begins_with'
163
165
  { :range_begins_with => val }
164
166
  end
@@ -166,7 +168,7 @@ module Dynamoid #:nodoc:
166
168
 
167
169
  def range_query
168
170
  opts = { :hash_value => query[source.hash_key] }
169
- if key = query.keys.find { |k| k.to_s.include?('.') }
171
+ query.keys.select { |k| k.to_s.include?('.') }.each do |key|
170
172
  opts.merge!(range_hash(key))
171
173
  end
172
174
  opts.merge(query_opts).merge(consistent_opts)
@@ -72,7 +72,7 @@ module Dynamoid #:nodoc:
72
72
  #
73
73
  # @since 0.2.0
74
74
  def create(attrs = {})
75
- attrs[:type] ? attrs[:type].constantize.new(attrs).tap(&:save) : new(attrs).tap(&:save)
75
+ build(attrs).tap(&:save)
76
76
  end
77
77
 
78
78
  # Initialize a new object and immediately save it to the database. Raise an exception if persistence failed.
@@ -83,7 +83,7 @@ module Dynamoid #:nodoc:
83
83
  #
84
84
  # @since 0.2.0
85
85
  def create!(attrs = {})
86
- attrs[:type] ? attrs[:type].constantize.new(attrs).tap(&:save!) : new(attrs).tap(&:save!)
86
+ build(attrs).tap(&:save!)
87
87
  end
88
88
 
89
89
  # Initialize a new object.
@@ -51,7 +51,15 @@ module Dynamoid #:nodoc:
51
51
  self.attributes = attributes.merge(name => {:type => type}.merge(options))
52
52
 
53
53
  define_method(named) { read_attribute(named) }
54
- define_method("#{named}?") { !read_attribute(named).nil? }
54
+ define_method("#{named}?") do
55
+ value = read_attribute(named)
56
+ case value
57
+ when true then true
58
+ when false, nil then false
59
+ else
60
+ !value.nil?
61
+ end
62
+ end
55
63
  define_method("#{named}=") {|value| write_attribute(named, value) }
56
64
  end
57
65
 
@@ -16,7 +16,15 @@ module Dynamoid
16
16
  module ClassMethods
17
17
 
18
18
  def table_name
19
- @table_name ||= "#{Dynamoid::Config.namespace}_#{options[:name] || base_class.name.split('::').last.downcase.pluralize}"
19
+ table_base_name = options[:name] || base_class.name.split('::').last
20
+ .downcase.pluralize
21
+ table_prefix = if Dynamoid::Config.namespace.nil? then
22
+ ''
23
+ else
24
+ "#{Dynamoid::Config.namespace}_"
25
+ end
26
+
27
+ @table_name ||= "#{table_prefix}#{table_base_name}"
20
28
  end
21
29
 
22
30
  # Creates a table.
@@ -32,5 +32,32 @@ module Dynamoid
32
32
  raise Dynamoid::Errors::DocumentNotValid.new(self) unless valid?
33
33
  save(:validate => false)
34
34
  end
35
+
36
+ module ClassMethods
37
+
38
+ # Override validates_presence_of to handle false values as present.
39
+ #
40
+ # @since 1.1.1
41
+ def validates_presence_of(*attr_names)
42
+ validates_with PresenceValidator, _merge_attributes(attr_names)
43
+ end
44
+
45
+ private
46
+
47
+ # Validates that the specified attributes are present (false or not blank).
48
+ class PresenceValidator < ActiveModel::EachValidator
49
+ # Validate the record for the record and value.
50
+ def validate_each(record, attr_name, value)
51
+ record.errors.add(attr_name, :blank, options) if not_present?(value)
52
+ end
53
+
54
+ private
55
+
56
+ # Check whether a value is not present.
57
+ def not_present?(value)
58
+ value.blank? && value != false
59
+ end
60
+ end
61
+ end
35
62
  end
36
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamoid-edge
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Symonds
@@ -16,7 +16,7 @@ authors:
16
16
  autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
- date: 2016-03-10 00:00:00.000000000 Z
19
+ date: 2016-03-30 00:00:00.000000000 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: activemodel
@@ -173,7 +173,7 @@ files:
173
173
  - LICENSE.txt
174
174
  - README.markdown
175
175
  - Rakefile
176
- - dynamoid-edge.gemspec
176
+ - dynamoid.gemspec
177
177
  - lib/dynamoid.rb
178
178
  - lib/dynamoid/adapter.rb
179
179
  - lib/dynamoid/adapter_plugin/aws_sdk_v2.rb
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  version: '0'
221
221
  requirements: []
222
222
  rubyforge_project:
223
- rubygems_version: 2.4.5
223
+ rubygems_version: 2.4.5.1
224
224
  signing_key:
225
225
  specification_version: 4
226
226
  summary: Dynamoid is an ORM for Amazon's DynamoDB