Parent

Class/Module Index [+]

Quicksearch

Mongoid::Fields::Serializable::Array

Defines the behaviour for array fields.

Public Instance Methods

serialize(object) click to toggle source

Serialize the object from the type defined in the model to a MongoDB compatible object to store.

@example Serialize the field.

field.serialize(object)

@param [ Object ] object The object to cast.

@return [ Array ] The converted object.

@since 2.1.0

# File lib/mongoid/fields/serializable/array.rb, line 20
def serialize(object)
  raise_or_return(object)
end

Protected Instance Methods

raise_or_return(value) click to toggle source

If the value is not an array or nil we will raise an error, otherwise return the value.

@example Raise or return the value.

field.raise_or_return([])

@param [ Object ] value The value to check.a

@raise [ InvalidType ] If not passed an array.

@return [ Array ] The array.

@since 2.1.0

# File lib/mongoid/fields/serializable/array.rb, line 39
def raise_or_return(value)
  unless value.nil? || value.is_a?(::Array)
    raise Mongoid::Errors::InvalidType.new(::Array, value)
  end
  value
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.