Method: Mongoid::Fields.option

Defined in:
lib/mongoid/fields.rb

.option(option_name, &block) ⇒ Object

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

No assumptions are made about what functionality 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.

Examples:

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

Parameters:

  • option_name (Symbol)

    the option name to match against

  • &block

    the handler to execute when the option is provided.



298
299
300
# File 'lib/mongoid/fields.rb', line 298

def option(option_name, &block)
  options[option_name] = block
end