Sha256: 63e9ee19e8400c0fa77a54a59bd2bb2763112746be09b3ddf5062238cb1a180d

Contents?: true

Size: 776 Bytes

Versions: 6

Compression:

Stored size: 776 Bytes

Contents

module Toy
  module Dolly
    extend ActiveSupport::Concern

    def initialize_copy(other)
      @_new_record = true
      @_destroyed  = false
      @attributes = {}.with_indifferent_access

      self.class.embedded_lists.each do |name, list|
        instance_variable_set(list.instance_variable, nil)
      end

      self.class.lists.each do |name, list|
        instance_variable_set(list.instance_variable, nil)
      end

      other.attributes.except('id').each do |key, value|
        value = value.duplicable? ? value.clone : value
        send("#{key}=", value)
      end

      other.class.embedded_lists.keys.each do |name|
        send("#{name}=", other.send(name).map(&:clone))
      end

      write_attribute(:id, self.class.next_key(self))
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
toystore-0.6.4 lib/toy/dolly.rb
toystore-0.6.3 lib/toy/dolly.rb
toystore-0.6.2 lib/toy/dolly.rb
toystore-0.6.1 lib/toy/dolly.rb
toystore-0.6 lib/toy/dolly.rb
toystore-0.5 lib/toy/dolly.rb