class Mongoid::Fields::Standard

def add_atomic_changes(document, name, key, mods, new, old)

Parameters:
  • old (Array) -- The old elements getting removed.
  • new (Array) -- The new elements to add.
  • mods (Hash) -- The current modifications.
  • key (String) -- The atomic location of the field.
  • name (String) -- The name of the field.
  • document (Document) -- The document to add to.

Other tags:
    Example: Add the atomic changes. -
def add_atomic_changes(document, name, key, mods, new, old)
  mods[key] = new
end

def association

Returns:
  • (Metadata) - The association metadata.

Other tags:
    Example: Get the metadata. -
def association
  @association ||= options[:association]
end

def default_name

Returns:
  • (String) - The method name.

Other tags:
    Example: Get the default name. -

Other tags:
    Api: - private
def default_name
  @default_name ||= "__#{name}_default__"
end

def define_default_method(object)

Parameters:
  • object (Class | Module) -- The class or module the field is

Other tags:
    Note: - Ruby's instance_exec was just too slow.

Other tags:
    Example: Define the method. -

Other tags:
    Api: - private
def define_default_method(object)
  object.__send__(:define_method, default_name, default_val)
end

def eval_default(doc)

Returns:
  • (Object) - The serialized default value.

Parameters:
  • doc (Document) -- The document the field belongs to.

Other tags:
    Example: Evaluate the default value. -
def eval_default(doc)
  if fields = doc.__selected_fields
    evaluated_default(doc) if included?(fields)
  else
    evaluated_default(doc)
  end
end

def evaluate_default_proc(doc)

Returns:
  • (Object) - The called proc.

Parameters:
  • doc (Document) -- The document.

Other tags:
    Example: Eval the default proc. -
def evaluate_default_proc(doc)
  serialize_default(doc.__send__(default_name))
end

def evaluated_default(doc)

Returns:
  • (Object) - The default value.

Parameters:
  • doc (Document) -- The doc being applied to.

Other tags:
    Example: Get the evaluated default. -
def evaluated_default(doc)
  if default_val.respond_to?(:call)
    evaluate_default_proc(doc)
  else
    serialize_default(default_val.__deep_copy__)
  end
end

def foreign_key?

Returns:
  • (true | false) - If the field is a foreign key.

Other tags:
    Example: Is the field a foreign key? -
def foreign_key?
  false
end

def included?(fields)

Returns:
  • (true | false) - If the field was included.

Parameters:
  • fields (Hash) -- The field limitations.

Other tags:
    Example: Is the field included? -
def included?(fields)
  (fields.values.first == 1 && fields[name.to_s] == 1) ||
    (fields.values.first == 0 && !fields.has_key?(name.to_s))
end

def initialize(name, options = {})

Options Hash: (**options)
  • :label (String) -- The field's label.
  • :default (Object) -- The default value for the field.
  • :type (Class) -- The class of the field.

Parameters:
  • options (Hash) -- The field options.

Other tags:
    Example: Create the new field. -
def initialize(name, options = {})
  @name = name
  @options = options
  @label = options[:label]
  @default_val = options[:default]
  # @todo: Durran, change API in 4.0 to take the class as a parameter.
  # This is here temporarily to address #2529 without changing the
  # constructor signature.
  if default_val.respond_to?(:call)
    define_default_method(options[:klass])
  end
end

def lazy?

Returns:
  • (true | false) - If the field is lazy.

Other tags:
    Example: Is the field lazy? -
def lazy?
  false
end

def localize_present?

Returns:
  • (true | false) - If the field enforces present.

Other tags:
    Example: Is the localized field enforcing values to be present? -
def localize_present?
  false
end

def localized?

Returns:
  • (true | false) - If the field is localized.

Other tags:
    Example: Is the field localized? -
def localized?
  false
end

def object_id_field?

Returns:
  • (true | false) - If the field is a BSON::ObjectId.

Other tags:
    Example: Is the field a BSON::ObjectId? -
def object_id_field?
  @object_id_field ||= (type == BSON::ObjectId)
end

def pre_processed?

Returns:
  • (true | false) - If the field's default is pre-processed.

Other tags:
    Example: Does the field pre-process the default? -
def pre_processed?
  @pre_processed ||=
    (options[:pre_processed] || (default_val && !default_val.is_a?(::Proc)))
end

def serialize_default(object)

Returns:
  • (Object) - The serialized default.

Parameters:
  • object (Object) -- The default.

Other tags:
    Example: Serialize the default value. -

Other tags:
    Api: - private
def serialize_default(object)
  mongoize(object)
end

def type

Returns:
  • (Class) - The name of the class.

Other tags:
    Example: Get the type. -
def type
  @type ||= options[:type] || Object
end