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



205
206
207
208
209
210
211
212
213
# File 'lib/mongoid/fields/serializable.rb', line 205

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