This module defines behaviour for fields.
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
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
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
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
Generated with the Darkfish Rdoc Generator 2.