Sha256: 103c20afffab270999c2555f2a5131f82ab1ed770ec10750b00f477f4e218ba2

Contents?: true

Size: 439 Bytes

Versions: 9

Compression:

Stored size: 439 Bytes

Contents

module Toy
  module Cloneable
    extend ActiveSupport::Concern

    def initialize_copy(other)
      instance_variables.each do |name|
        instance_variable_set(name, nil)
      end

      @attributes  = {}

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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
toystore-0.13.0 lib/toy/cloneable.rb
toystore-0.12.0 lib/toy/cloneable.rb
toystore-0.11.0 lib/toy/cloneable.rb
toystore-0.10.4 lib/toy/cloneable.rb
toystore-0.10.3 lib/toy/cloneable.rb
toystore-0.10.2 lib/toy/cloneable.rb
toystore-0.10.1 lib/toy/cloneable.rb
toystore-0.10.0 lib/toy/cloneable.rb
toystore-0.9.0 lib/toy/cloneable.rb