Class: Mongoid::Fields::Standard
- Inherits:
-
Object
- Object
- Mongoid::Fields::Standard
- Defined in:
- lib/mongoid/fields/standard.rb
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) default_val
Defines the behaviour for defined fields in the document.
-
- (Object) label
Defines the behaviour for defined fields in the document.
-
- (Object) name
Defines the behaviour for defined fields in the document.
-
- (Object) options
Defines the behaviour for defined fields in the document.
Instance Method Summary (collapse)
-
- (Object) add_atomic_changes(document, name, key, mods, new, old)
Adds the atomic changes for this type of resizable field.
-
- (Constraint) constraint
Get the constraint from the metadata once.
-
- (Array) demongoized_identity_for(object)
Compute the demongoized identity of an object.
-
- (Object) eval_default(doc)
Evaluate the default value and return it.
-
- (true, false) foreign_key?
Is this field a foreign key?.
-
- (Standard) initialize(name, options = {})
constructor
Create the new field with a name and optional additional options.
-
- (true, false) localized?
Is the field localized or not?.
-
- (Metadata) metadata
Get the metadata for the field if its a foreign key.
-
- (true, false) object_id_field?
Is the field a BSON::ObjectId?.
-
- (true, false) pre_processed?
Does the field pre-process it's default value?.
-
- (Class) type
Get the type of this field - inferred from the class name.
-
- (true, false) versioned?
Is this field included in versioned attributes?.
Constructor Details
- (Standard) initialize(name, options = {})
Create the new field with a name and optional additional options.
98 99 100 101 102 103 |
# File 'lib/mongoid/fields/standard.rb', line 98 def initialize(name, = {}) @name = name @options = @label = [:label] @default_val = [:default] end |
Instance Attribute Details
- (Object) default_val
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 |
- (Object) label
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 |
- (Object) name
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 |
- (Object) options
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
- (Object) add_atomic_changes(document, name, key, mods, new, old)
Adds the atomic changes for this type of resizable field.
field.add_atomic_changes(doc, "key", {}, [], [])
39 40 41 |
# File 'lib/mongoid/fields/standard.rb', line 39 def add_atomic_changes(document, name, key, mods, new, old) mods[key] = new end |
- (Constraint) constraint
Get the constraint from the metadata once.
51 52 53 |
# File 'lib/mongoid/fields/standard.rb', line 51 def constraint @constraint ||= .constraint end |
- (Array) demongoized_identity_for(object)
Compute the demongoized identity of an object
22 23 24 |
# File 'lib/mongoid/fields/standard.rb', line 22 def demongoized_identity_for(object) [ object.object_id, object.hash ] end |
- (Object) eval_default(doc)
Evaluate the default value and return it. Will handle the serialization, proc calls, and duplication if necessary.
66 67 68 69 70 71 72 |
# File 'lib/mongoid/fields/standard.rb', line 66 def eval_default(doc) if fields = Threaded.selection evaluated_default(doc) if included?(fields) else evaluated_default(doc) end end |
- (true, false) foreign_key?
Is this field a foreign key?
82 83 84 |
# File 'lib/mongoid/fields/standard.rb', line 82 def foreign_key? false end |
- (true, false) localized?
Is the field localized or not?
113 114 115 |
# File 'lib/mongoid/fields/standard.rb', line 113 def localized? false end |
- (Metadata) metadata
Get the metadata for the field if its a foreign key.
125 126 127 |
# File 'lib/mongoid/fields/standard.rb', line 125 def @metadata ||= [:metadata] end |
- (true, false) object_id_field?
Is the field a BSON::ObjectId?
137 138 139 |
# File 'lib/mongoid/fields/standard.rb', line 137 def object_id_field? @object_id_field ||= (type == Moped::BSON::ObjectId) end |
- (true, false) pre_processed?
Does the field pre-process it's default value?
149 150 151 152 |
# File 'lib/mongoid/fields/standard.rb', line 149 def pre_processed? @pre_processed ||= ([:pre_processed] || (default_val && !default_val.is_a?(::Proc))) end |
- (Class) type
Get the type of this field - inferred from the class name.
162 163 164 |
# File 'lib/mongoid/fields/standard.rb', line 162 def type @type ||= [:type] || Object end |
- (true, false) versioned?
Is this field included in versioned attributes?
174 175 176 |
# File 'lib/mongoid/fields/standard.rb', line 174 def versioned? @versioned ||= ([:versioned].nil? ? true : [:versioned]) end |