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



243
244
245
246
247
248
249
250
251
# File 'lib/mongoid/fields/serializable.rb', line 243

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]
  end
end