Module: Dynamoid::Dirty::DeepDupper
- Defined in:
- lib/dynamoid/dirty.rb
Class Method Summary collapse
Class Method Details
.dup_attribute(value, type_options) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/dynamoid/dirty.rb', line 328 def self.dup_attribute(value, ) type, of = .values_at(:type, :of) case value when NilClass, TrueClass, FalseClass, Numeric, Symbol, IO # Till Ruby 2.4 these immutable objects could not be duplicated. # IO objects (used for the binary type) cannot be duplicated as well. value when Array if of.is_a? Class # custom type value.map { |e| dup_attribute(e, type: of) } else value.deep_dup end when Set Set.new(value.map { |e| dup_attribute(e, type: of) }) else if type.is_a? Class # custom type dump = Dumping.dump_field(value, ) Undumping.undump_field(dump.deep_dup, ) else value.deep_dup end end end |
.dup_attributes(attributes, klass) ⇒ Object
320 321 322 323 324 325 326 |
# File 'lib/dynamoid/dirty.rb', line 320 def self.dup_attributes(attributes, klass) attributes.map do |name, value| = klass.attributes[name.to_sym] value_duplicate = dup_attribute(value, ) [name, value_duplicate] end.to_h end |