Module: Mongoid::Fields
- Extended by:
- ActiveSupport::Concern
- Included in:
- Components
- Defined in:
- lib/mongoid/fields.rb,
lib/mongoid/fields/mappings.rb,
lib/mongoid/fields/internal/set.rb,
lib/mongoid/fields/serializable.rb,
lib/mongoid/fields/internal/date.rb,
lib/mongoid/fields/internal/hash.rb,
lib/mongoid/fields/internal/time.rb,
lib/mongoid/fields/internal/array.rb,
lib/mongoid/fields/internal/float.rb,
lib/mongoid/fields/internal/range.rb,
lib/mongoid/fields/internal/bignum.rb,
lib/mongoid/fields/internal/binary.rb,
lib/mongoid/fields/internal/fixnum.rb,
lib/mongoid/fields/internal/object.rb,
lib/mongoid/fields/internal/string.rb,
lib/mongoid/fields/internal/symbol.rb,
lib/mongoid/fields/internal/boolean.rb,
lib/mongoid/fields/internal/integer.rb,
lib/mongoid/fields/internal/date_time.rb,
lib/mongoid/fields/internal/localized.rb,
lib/mongoid/fields/internal/nil_class.rb,
lib/mongoid/fields/internal/object_id.rb,
lib/mongoid/fields/internal/true_class.rb,
lib/mongoid/fields/internal/big_decimal.rb,
lib/mongoid/fields/internal/false_class.rb,
lib/mongoid/fields/internal/timekeeping.rb,
lib/mongoid/fields/internal/time_with_zone.rb,
lib/mongoid/fields/internal/foreign_keys/array.rb,
lib/mongoid/fields/internal/foreign_keys/object.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ClassMethods, Internal, Mappings, Serializable
Class Method Summary collapse
-
.option(option_name, &block) ⇒ Object
Stores the provided block to be run when the option name specified is defined on a field.
-
.options ⇒ Hash
Return a map of custom option names to their handlers.
Instance Method Summary collapse
-
#apply_default(name) ⇒ Object
Applies a single default value for the given name.
-
#apply_defaults ⇒ Object
Apply all the defaults at once.
-
#apply_non_proc_defaults ⇒ Array<String ] The names of the non-proc defaults.
Apply all default values to the document which are not procs.
-
#apply_proc_defaults ⇒ Array<String ] The names of the proc defaults.
Apply all default values to the document which are procs.
-
#defaults ⇒ Array<String ] The names of all defaults.
Get a list of all the default fields for the model.
Class Method Details
.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 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.
145 146 147 |
# File 'lib/mongoid/fields.rb', line 145 def option(option_name, &block) [option_name] = block end |
.options ⇒ Hash
Return a map of custom option names to their handlers.
158 159 160 |
# File 'lib/mongoid/fields.rb', line 158 def @options ||= {} end |
Instance Method Details
#apply_default(name) ⇒ Object
Applies a single default value for the given name.
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/mongoid/fields.rb', line 91 def apply_default(name) unless attributes.has_key?(name) if field = fields[name] default = field.eval_default(self) unless default.nil? attribute_will_change!(name) attributes[name] = default end end end end |
#apply_defaults ⇒ Object
Apply all the defaults at once.
109 110 111 112 |
# File 'lib/mongoid/fields.rb', line 109 def apply_defaults apply_non_proc_defaults apply_proc_defaults end |
#apply_non_proc_defaults ⇒ Array<String ] The names of the non-proc defaults.
Apply all default values to the document which are not procs.
63 64 65 66 67 |
# File 'lib/mongoid/fields.rb', line 63 def apply_non_proc_defaults non_proc_defaults.each do |name| apply_default(name) end end |