Sha256: 7667a1c84d8f92460c852590c60130c30ccc7587b9b6a252a4d64ae7587c0fbd

Contents?: true

Size: 1001 Bytes

Versions: 59

Compression:

Stored size: 1001 Bytes

Contents

# encoding: utf-8
module Mongoid
  module Persistable

    # Defines behaviour for $rename operations.
    #
    # @since 4.0.0
    module Renamable
      extend ActiveSupport::Concern

      # Rename fields from one value to another via $rename.
      #
      # @example Rename the fields.
      #   document.rename(title: "salutation", name: "nombre")
      #
      # @note This does not work for fields in embeds many relations.
      #
      # @param [ Hash ] renames The rename pairs of old name/new name.
      #
      # @return [ Document ] The document.
      #
      # @since 4.0.0
      def rename(renames)
        prepare_atomic_operation do |ops|
          process_atomic_operations(renames) do |old_field, new_field|
            new_name = new_field.to_s
            attributes[new_name] = attributes.delete(old_field)
            ops[atomic_attribute_name(old_field)] = atomic_attribute_name(new_name)
          end
          { "$rename" => ops }
        end
      end
    end
  end
end

Version data entries

59 entries across 55 versions & 3 rubygems

Version Path
mongoid-7.0.13 lib/mongoid/persistable/renamable.rb
mongoid-7.0.12 lib/mongoid/persistable/renamable.rb
mongoid-6.4.8 lib/mongoid/persistable/renamable.rb
mongoid-7.0.11 lib/mongoid/persistable/renamable.rb
mongoid-7.0.10 lib/mongoid/persistable/renamable.rb
mongoid-6.4.7 lib/mongoid/persistable/renamable.rb
mongoid-6.4.5 lib/mongoid/persistable/renamable.rb
mongoid-7.0.8 lib/mongoid/persistable/renamable.rb
mongoid-7.0.7 lib/mongoid/persistable/renamable.rb
mongoid-7.0.6 lib/mongoid/persistable/renamable.rb
mongoid-5.4.1 lib/mongoid/persistable/renamable.rb
mongoid-7.0.5 lib/mongoid/persistable/renamable.rb
mongoid-7.0.4 lib/mongoid/persistable/renamable.rb
mongoid-6.4.4 lib/mongoid/persistable/renamable.rb
mongoid-7.0.3 lib/mongoid/persistable/renamable.rb
mongoid-6.4.2 lib/mongoid/persistable/renamable.rb
mongoid-7.0.2 lib/mongoid/persistable/renamable.rb
mongoid-7.0.1 lib/mongoid/persistable/renamable.rb
mongoid-6.4.1 lib/mongoid/persistable/renamable.rb
mongoid-5.4.0 lib/mongoid/persistable/renamable.rb