dynamoid 3.14.0 → 3.15.0

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.
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'yaml'
4
+
3
5
  module Dynamoid
4
6
  # @private
5
7
  module Undumping
@@ -40,7 +42,7 @@ module Dynamoid
40
42
  when :serialized then SerializedUndumper
41
43
  when :boolean then BooleanUndumper
42
44
  when :binary then BinaryUndumper
43
- when Class then CustomTypeUndumper
45
+ when Module then CustomTypeUndumper
44
46
  end
45
47
 
46
48
  if undumper_class.present?
@@ -100,7 +102,7 @@ module Dynamoid
100
102
  end
101
103
 
102
104
  class SetUndumper < Base
103
- ALLOWED_TYPES = %i[string integer number date datetime serialized].freeze
105
+ ALLOWED_TYPES = %i[string integer number date datetime serialized binary].freeze
104
106
 
105
107
  def process(set)
106
108
  if @options.key?(:of)
@@ -122,7 +124,7 @@ module Dynamoid
122
124
  end
123
125
 
124
126
  def allowed_type?
125
- ALLOWED_TYPES.include?(element_type) || element_type.is_a?(Class)
127
+ ALLOWED_TYPES.include?(element_type) || element_type.is_a?(Module)
126
128
  end
127
129
 
128
130
  def element_type
@@ -145,7 +147,7 @@ module Dynamoid
145
147
  end
146
148
 
147
149
  class ArrayUndumper < Base
148
- ALLOWED_TYPES = %i[string integer number date datetime serialized].freeze
150
+ ALLOWED_TYPES = %i[string integer number date datetime serialized binary].freeze
149
151
 
150
152
  def process(array)
151
153
  if @options.key?(:of)
@@ -167,7 +169,7 @@ module Dynamoid
167
169
  end
168
170
 
169
171
  def allowed_type?
170
- ALLOWED_TYPES.include?(element_type) || element_type.is_a?(Class)
172
+ ALLOWED_TYPES.include?(element_type) || element_type.is_a?(Module)
171
173
  end
172
174
 
173
175
  def element_type
@@ -236,32 +238,45 @@ module Dynamoid
236
238
  end
237
239
 
238
240
  class SerializedUndumper < Base
239
- # We must use YAML.safe_load in Ruby 3.1 to handle serialized Set class
240
- minimum_ruby_version = ->(version) { Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(version) }
241
-
242
- # Once we drop support for Rubies older than 2.6 we can remove this condition (with major version bump)!
243
- # YAML_SAFE_LOAD = minimum_ruby_version.call("2.6")
244
- # But we don't want to change behavior for Ruby <= 3.0 that has been using the gem, without a major version bump
245
- YAML_SAFE_LOAD = minimum_ruby_version.call('3.1')
246
-
247
241
  def process(value)
248
242
  if @options[:serializer]
249
243
  @options[:serializer].load(value)
250
- elsif YAML_SAFE_LOAD
251
- # The classes listed in permitted classes are added to the default set of "safe loadable" classes.
252
- # TrueClass
253
- # FalseClass
254
- # NilClass
255
- # Integer
256
- # Float
257
- # String
258
- # Array
259
- # Hash
260
- YAML.safe_load(value, permitted_classes: [Symbol, Set, Date, Time, DateTime])
244
+ elsif Dynamoid.config.use_yaml_unsafe_load
245
+ yaml_unsafe_load(value)
261
246
  else
247
+ yaml_safe_load(value)
248
+ end
249
+ end
250
+
251
+ private
252
+
253
+ # `YAML.unsafe_load` was introduced in Psych 3.3.2 (Ruby 3.0).
254
+ # `YAML.load` was unsafe until Psych 4.0.0 (Ruby 3.1+).
255
+ if YAML.respond_to?(:unsafe_load)
256
+ def yaml_unsafe_load(value)
257
+ YAML.unsafe_load(value)
258
+ end
259
+ else
260
+ def yaml_unsafe_load(value)
262
261
  YAML.load(value)
263
262
  end
264
263
  end
264
+
265
+ # The classes listed in permitted classes are added to the default
266
+ # set of "safe loadable" classes:
267
+ # TrueClass, FalseClass, NilClass, Integer, Float, String, Array, Hash
268
+ #
269
+ # Permitted classes were accepted as a positional parameter until Psych 3.1.0 (Ruby 2.6),
270
+ # and as a keyword argument in later versions.
271
+ if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
272
+ def yaml_safe_load(value)
273
+ YAML.safe_load(value, permitted_classes: Dynamoid.config.yaml_permitted_classes)
274
+ end
275
+ else
276
+ def yaml_safe_load(value)
277
+ YAML.safe_load(value, Dynamoid.config.yaml_permitted_classes)
278
+ end
279
+ end
265
280
  end
266
281
 
267
282
  class BooleanUndumper < Base
@@ -285,6 +300,8 @@ module Dynamoid
285
300
 
286
301
  class BinaryUndumper < Base
287
302
  def process(value)
303
+ return nil if value.nil?
304
+
288
305
  store_as_binary = if @options[:store_as_native_binary].nil?
289
306
  Dynamoid.config.store_binary_as_native
290
307
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dynamoid
4
- VERSION = '3.14.0'
4
+ VERSION = '3.15.0'
5
5
  end
data/lib/dynamoid.rb CHANGED
@@ -44,7 +44,9 @@ require 'dynamoid/middleware/identity_map'
44
44
  require 'dynamoid/railtie' if defined?(Rails)
45
45
 
46
46
  module Dynamoid
47
- extend self
47
+ autoload :TestHelper, 'dynamoid/test_helper'
48
+
49
+ extend self # rubocop:disable Style/ModuleFunction
48
50
 
49
51
  def configure
50
52
  block_given? ? yield(Dynamoid::Config) : Dynamoid::Config
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.14.0
4
+ version: 3.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Symonds
@@ -241,10 +241,12 @@ files:
241
241
  - lib/dynamoid/tasks.rb
242
242
  - lib/dynamoid/tasks/database.rake
243
243
  - lib/dynamoid/tasks/database.rb
244
+ - lib/dynamoid/test_helper.rb
244
245
  - lib/dynamoid/transactions.rb
245
246
  - lib/dynamoid/transactions/mutation.rb
246
247
  - lib/dynamoid/transactions/mutation/base.rb
247
248
  - lib/dynamoid/transactions/mutation/builders/delete_request_builder.rb
249
+ - lib/dynamoid/transactions/mutation/builders/put_request_builder.rb
248
250
  - lib/dynamoid/transactions/mutation/builders/update_request_builder.rb
249
251
  - lib/dynamoid/transactions/mutation/create.rb
250
252
  - lib/dynamoid/transactions/mutation/delete_with_instance.rb
@@ -269,10 +271,10 @@ licenses:
269
271
  - MIT
270
272
  metadata:
271
273
  homepage_uri: http://github.com/Dynamoid/dynamoid
272
- source_code_uri: https://github.com/Dynamoid/dynamoid/tree/v3.14.0
273
- changelog_uri: https://github.com/Dynamoid/dynamoid/blob/v3.14.0/CHANGELOG.md
274
+ source_code_uri: https://github.com/Dynamoid/dynamoid/tree/v3.15.0
275
+ changelog_uri: https://github.com/Dynamoid/dynamoid/blob/v3.15.0/CHANGELOG.md
274
276
  bug_tracker_uri: https://github.com/Dynamoid/dynamoid/issues
275
- documentation_uri: https://www.rubydoc.info/gems/dynamoid/3.14.0
277
+ documentation_uri: https://www.rubydoc.info/gems/dynamoid/3.15.0
276
278
  funding_uri: https://opencollective.com/dynamoid
277
279
  wiki_uri: https://github.com/Dynamoid/dynamoid/wiki
278
280
  rubygems_mfa_required: 'true'