Sha256: 370a67fcd2641fa99073cba37a87b155865fa4d0222c06ac076c849176ff821c
Contents?: true
Size: 1.19 KB
Versions: 27
Compression:
Stored size: 1.19 KB
Contents
# frozen_string_literal: true # encoding: utf-8 module Mongoid module Persistable # Defines behavior 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 associations. # # @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 if executing_atomically? process_attribute new_name, attributes[old_field] process_attribute old_field, nil else attributes[new_name] = attributes.delete(old_field) end ops[atomic_attribute_name(old_field)] = atomic_attribute_name(new_name) end { "$rename" => ops } end end end end end
Version data entries
27 entries across 27 versions & 2 rubygems