Sha256: b8dbd24a6fadb52edde5fc4c7dd8c95f45f69f025f09a212113e78409777671e

Contents?: true

Size: 644 Bytes

Versions: 15

Compression:

Stored size: 644 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Clone
      extend ActiveSupport::Concern

      def initialize_copy(other)
        @_new       = true
        @_destroyed = false
        remove_instance_variable :@_id if instance_variable_defined?(:@_id)
        init_ivars

        associations.each do |name, association|
          instance_variable_set(association.ivar, nil)
        end
        self.attributes = other.attributes.clone.except(:_id).inject({}) do |hash, entry|
          key, value = entry
          hash[key] = value.duplicable? ? value.clone : value
          hash
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mongo_mapper-0.17.0 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.16.0 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.15.6 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.15.5 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.15.4 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.15.3 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.15.2 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.15.1 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.15.0 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.14.0 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.14.0.rc1 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.13.1 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.13.0 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.13.0.beta2 lib/mongo_mapper/plugins/clone.rb
mongo_mapper-0.13.0.beta1 lib/mongo_mapper/plugins/clone.rb