Module: Mongoid::Fields::Serializable::ClassMethods

Defined in:
lib/mongoid/fields/serializable.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#instantiate(name, options = {}) ⇒ Object

Create the new field with a name and optional additional options.

Examples:

Create the new field.

Field.new(:name, :type => String)

Parameters:

  • options (Hash) (defaults to: {})

    The field options.

Options Hash (options):

  • :type (Class)

    The class of the field.

  • :default (Object)

    The default value for the field.

  • :label (String)

    The field’s label.

Since:

  • 2.1.0



171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/mongoid/fields/serializable.rb', line 171

def instantiate(name, options = {})
  allocate.tap do |field|
    field.name = name
    field.options = options
    field.label = options[:label]
    field.localize = options[:localize]
    field.default_val = options[:default]
    unless field.default_val
      field.default_val = {} if field.localized?
    end
  end
end