Sha256: 60785330ef829644198b081df314589f2ceb0aedb20fe18c198896485386871f

Contents?: true

Size: 847 Bytes

Versions: 3

Compression:

Stored size: 847 Bytes

Contents

# frozen_string_literal: true

# :nodoc

module Mongoid
  # This module defines behaviour for fields.
  module Fields
    module ClassMethods
      # Replace a field with a new type.
      #
      # @example Replace the field.
      #   Model.replace_field("_id", String)
      #
      # @param [ String ] name The name of the field.
      # @param [ Class ] type The new type of field.
      # @param [ Boolean ] localize The option to localize or not the field.
      #
      # @return [ Serializable ] The new field.
      #
      # @since 2.1.0
      def replace_field(name, type, localize = false)
        # puts "fields[#{name}] = #{fields[name.to_s].inspect} / #{fields.keys.inspect}" # DEBUG
        remove_defaults(name)
        add_field(name, fields[name.to_s].options.merge(type: type, localize: localize))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
custom_fields-2.14.0.alpha1 lib/custom_fields/extensions/mongoid/fields.rb
custom_fields-2.13.1 lib/custom_fields/extensions/mongoid/fields.rb
custom_fields-2.13.0 lib/custom_fields/extensions/mongoid/fields.rb