Class: Mongoid::Fields::Standard
- Inherits:
-
Object
- Object
- Mongoid::Fields::Standard
- Extended by:
- Forwardable
- Defined in:
- lib/mongoid/fields/standard.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default_val ⇒ Object
Defines the behavior for defined fields in the document.
-
#label ⇒ Object
Defines the behavior for defined fields in the document.
-
#name ⇒ Object
Defines the behavior for defined fields in the document.
-
#options ⇒ Object
Defines the behavior for defined fields in the document.
Instance Method Summary collapse
-
#add_atomic_changes(document, name, key, mods, new, old) ⇒ Object
Adds the atomic changes for this type of resizable field.
-
#association ⇒ Metadata
Get the metadata for the field if its a foreign key.
-
#eval_default(doc) ⇒ Object
Evaluate the default value and return it.
-
#foreign_key? ⇒ true | false
Is this field a foreign key?.
-
#initialize(name, options = {}) ⇒ Standard
constructor
Create the new field with a name and optional additional options.
-
#lazy? ⇒ true | false
Does this field do lazy default evaluation?.
-
#localize_present? ⇒ true | false
Is the localized field enforcing values to be present?.
-
#localized? ⇒ true | false
Is the field localized or not?.
-
#object_id_field? ⇒ true | false
Is the field a BSON::ObjectId?.
-
#pre_processed? ⇒ true | false
Does the field pre-process its default value?.
-
#type ⇒ Class
Get the type of this field - inferred from the class name.
Constructor Details
#initialize(name, options = {}) ⇒ Standard
Create the new field with a name and optional additional options.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mongoid/fields/standard.rb', line 66 def initialize(name, = {}) @name = name @options = @label = [:label] @default_val = [:default] # @todo: Durran, change API in 4.0 to take the class as a parameter. # This is here temporarily to address #2529 without changing the # constructor signature. if default_val.respond_to?(:call) define_default_method([:klass]) end end |
Instance Attribute Details
#default_val ⇒ Object
Defines the behavior for defined fields in the document. Set readers for the instance variables.
10 11 12 |
# File 'lib/mongoid/fields/standard.rb', line 10 def default_val @default_val end |
#label ⇒ Object
Defines the behavior for defined fields in the document. Set readers for the instance variables.
10 11 12 |
# File 'lib/mongoid/fields/standard.rb', line 10 def label @label end |
#name ⇒ Object
Defines the behavior for defined fields in the document. Set readers for the instance variables.
10 11 12 |
# File 'lib/mongoid/fields/standard.rb', line 10 def name @name end |
#options ⇒ Object
Defines the behavior for defined fields in the document. Set readers for the instance variables.
10 11 12 |
# File 'lib/mongoid/fields/standard.rb', line 10 def @options end |
Instance Method Details
#add_atomic_changes(document, name, key, mods, new, old) ⇒ Object
Adds the atomic changes for this type of resizable field.
field.add_atomic_changes(doc, “key”, {}, [], [])
25 26 27 |
# File 'lib/mongoid/fields/standard.rb', line 25 def add_atomic_changes(document, name, key, mods, new, old) mods[key] = new end |
#association ⇒ Metadata
Get the metadata for the field if its a foreign key.
116 117 118 |
# File 'lib/mongoid/fields/standard.rb', line 116 def association @association ||= [:association] end |
#eval_default(doc) ⇒ Object
Evaluate the default value and return it. Will handle the serialization, proc calls, and duplication if necessary.
38 39 40 41 42 43 44 |
# File 'lib/mongoid/fields/standard.rb', line 38 def eval_default(doc) if fields = doc.__selected_fields evaluated_default(doc) if included?(fields) else evaluated_default(doc) end end |
#foreign_key? ⇒ true | false
Is this field a foreign key?
52 53 54 |
# File 'lib/mongoid/fields/standard.rb', line 52 def foreign_key? false end |
#lazy? ⇒ true | false
Does this field do lazy default evaluation?
86 87 88 |
# File 'lib/mongoid/fields/standard.rb', line 86 def lazy? false end |
#localize_present? ⇒ true | false
Is the localized field enforcing values to be present?
106 107 108 |
# File 'lib/mongoid/fields/standard.rb', line 106 def localize_present? false end |
#localized? ⇒ true | false
Is the field localized or not?
96 97 98 |
# File 'lib/mongoid/fields/standard.rb', line 96 def localized? false end |
#object_id_field? ⇒ true | false
Is the field a BSON::ObjectId?
126 127 128 |
# File 'lib/mongoid/fields/standard.rb', line 126 def object_id_field? @object_id_field ||= (type == BSON::ObjectId) end |
#pre_processed? ⇒ true | false
Does the field pre-process its default value?
136 137 138 139 |
# File 'lib/mongoid/fields/standard.rb', line 136 def pre_processed? @pre_processed ||= ([:pre_processed] || (default_val && !default_val.is_a?(::Proc))) end |
#type ⇒ Class
Get the type of this field - inferred from the class name.
147 148 149 |
# File 'lib/mongoid/fields/standard.rb', line 147 def type @type ||= [:type] || Object end |