Sha256: e03d3cead5a5599ff988893a036edb6f71f2f253e86a38758ff70632c9615741

Contents?: true

Size: 752 Bytes

Versions: 7

Compression:

Stored size: 752 Bytes

Contents

module Toy
  module Dolly
    extend ActiveSupport::Concern

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

      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

7 entries across 7 versions & 1 rubygems

Version Path
toystore-0.8.3 lib/toy/dolly.rb
toystore-0.8.2 lib/toy/dolly.rb
toystore-0.8.1 lib/toy/dolly.rb
toystore-0.8.0 lib/toy/dolly.rb
toystore-0.7.0 lib/toy/dolly.rb
toystore-0.6.6 lib/toy/dolly.rb
toystore-0.6.5 lib/toy/dolly.rb