Class: Mongoid::Fields::Standard
- Inherits:
-
Object
- Object
- Mongoid::Fields::Standard
- Defined in:
- lib/mongoid/fields/standard.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#default_val ⇒ Object
Defines the behaviour for defined fields in the document.
-
#label ⇒ Object
Defines the behaviour for defined fields in the document.
-
#name ⇒ Object
Defines the behaviour for defined fields in the document.
-
#options ⇒ Object
Defines the behaviour 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.
-
#constraint ⇒ Constraint
Get the constraint from the metadata once.
-
#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?.
-
#localized? ⇒ true, false
Is the field localized or not?.
-
#metadata ⇒ Metadata
Get the metadata for the field if its a foreign key.
-
#object_id_field? ⇒ true, false
Is the field a Moped::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.
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/mongoid/fields/standard.rb', line 84 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 behaviour for defined fields in the document. Set readers for the instance variables.
8 9 10 |
# File 'lib/mongoid/fields/standard.rb', line 8 def default_val @default_val end |
#label ⇒ Object
Defines the behaviour for defined fields in the document. Set readers for the instance variables.
8 9 10 |
# File 'lib/mongoid/fields/standard.rb', line 8 def label @label end |
#name ⇒ Object
Defines the behaviour for defined fields in the document. Set readers for the instance variables.
8 9 10 |
# File 'lib/mongoid/fields/standard.rb', line 8 def name @name end |
#options ⇒ Object
Defines the behaviour for defined fields in the document. Set readers for the instance variables.
8 9 10 |
# File 'lib/mongoid/fields/standard.rb', line 8 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 |
#constraint ⇒ Constraint
Get the constraint from the metadata once.
37 38 39 |
# File 'lib/mongoid/fields/standard.rb', line 37 def constraint @constraint ||= .constraint end |
#eval_default(doc) ⇒ Object
Evaluate the default value and return it. Will handle the serialization, proc calls, and duplication if necessary.
52 53 54 55 56 57 58 |
# File 'lib/mongoid/fields/standard.rb', line 52 def eval_default(doc) if fields = Threaded.selection(doc.criteria_instance_id) evaluated_default(doc) if included?(fields) else evaluated_default(doc) end end |
#foreign_key? ⇒ true, false
Is this field a foreign key?
68 69 70 |
# File 'lib/mongoid/fields/standard.rb', line 68 def foreign_key? false end |
#lazy? ⇒ true, false
Does this field do lazy default evaluation?
106 107 108 |
# File 'lib/mongoid/fields/standard.rb', line 106 def lazy? false end |
#localized? ⇒ true, false
Is the field localized or not?
118 119 120 |
# File 'lib/mongoid/fields/standard.rb', line 118 def localized? false end |
#metadata ⇒ Metadata
Get the metadata for the field if its a foreign key.
130 131 132 |
# File 'lib/mongoid/fields/standard.rb', line 130 def @metadata ||= [:metadata] end |
#object_id_field? ⇒ true, false
Is the field a Moped::BSON::ObjectId?
142 143 144 |
# File 'lib/mongoid/fields/standard.rb', line 142 def object_id_field? @object_id_field ||= (type == Moped::BSON::ObjectId) end |
#pre_processed? ⇒ true, false
Does the field pre-process its default value?
154 155 156 157 |
# File 'lib/mongoid/fields/standard.rb', line 154 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.
167 168 169 |
# File 'lib/mongoid/fields/standard.rb', line 167 def type @type ||= [:type] || Object end |