Class/Module Index [+]

Quicksearch

Mongoid::Fields

This module defines behaviour for fields.

Public Instance Methods

defaults() click to toggle source

Get the default fields.

@note Refactored from using delegate for class load performance.

@example Get the defaults.

model.defaults

@return [ Array<String> ] The default field names.

# File lib/mongoid/fields.rb, line 50
def defaults
  self.class.defaults
end
fields() click to toggle source

Get the document’s fields.

@note Refactored from using delegate for class load performance.

@example Get the fields.

model.fields

@return [ Hash ] The fields.

# File lib/mongoid/fields.rb, line 62
def fields
  self.class.fields
end

Public Class Methods

option(option_name, &block) click to toggle source

Stores the provided block to be run when the option name specified is defined on a field.

No assumptions are made about what sort of work the handler might perform, so it will always be called if the `option_name` key is provided in the field definition – even if it is false or nil.

@example

Mongoid::Fields.option :required do |model, field, value|
  model.validates_presence_of field if value
end

@param [ Symbol ] option_name the option name to match against @param [ Proc ] block the handler to execute when the option is

provided.

@since 2.1.0

# File lib/mongoid/fields.rb, line 85
def option(option_name, &block)
  options[option_name] = block
end
options() click to toggle source

Return a map of custom option names to their handlers.

@example

Mongoid::Fields.options
# => { :required => #<Proc:0x00000100976b38> }

@return [ Hash ] the option map

@since 2.1.0

# File lib/mongoid/fields.rb, line 98
def options
  @options ||= {}
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.