Module: Mongoid::Fields::Serializable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Array, BigDecimal, Binary, Boolean, Date, DateTime, Float, ForeignKeys::Array, ForeignKeys::Object, Hash, Integer, Localized, NilClass, Object, ObjectId, Range, Set, String, Symbol, Time, TimeWithZone
- Defined in:
- lib/mongoid/fields/serializable.rb,
lib/mongoid/fields/serializable/set.rb,
lib/mongoid/fields/serializable/date.rb,
lib/mongoid/fields/serializable/hash.rb,
lib/mongoid/fields/serializable/time.rb,
lib/mongoid/fields/serializable/array.rb,
lib/mongoid/fields/serializable/float.rb,
lib/mongoid/fields/serializable/range.rb,
lib/mongoid/fields/serializable/bignum.rb,
lib/mongoid/fields/serializable/binary.rb,
lib/mongoid/fields/serializable/fixnum.rb,
lib/mongoid/fields/serializable/object.rb,
lib/mongoid/fields/serializable/string.rb,
lib/mongoid/fields/serializable/symbol.rb,
lib/mongoid/fields/serializable/boolean.rb,
lib/mongoid/fields/serializable/integer.rb,
lib/mongoid/fields/serializable/date_time.rb,
lib/mongoid/fields/serializable/localized.rb,
lib/mongoid/fields/serializable/nil_class.rb,
lib/mongoid/fields/serializable/object_id.rb,
lib/mongoid/fields/serializable/big_decimal.rb,
lib/mongoid/fields/serializable/timekeeping.rb,
lib/mongoid/fields/serializable/time_with_zone.rb,
lib/mongoid/fields/serializable/foreign_keys/array.rb,
lib/mongoid/fields/serializable/foreign_keys/object.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ClassMethods, ForeignKeys, Timekeeping Classes: Array, BigDecimal, Bignum, Binary, Boolean, Date, DateTime, Fixnum, Float, Hash, Integer, Localized, NilClass, Object, ObjectId, Range, Set, String, Symbol, Time, TimeWithZone
Instance Attribute Summary collapse
-
#default_val ⇒ Object
Set readers for the instance variables.
-
#label ⇒ Object
Set readers for the instance variables.
-
#localize ⇒ Object
Set readers for the instance variables.
-
#name ⇒ Object
Set readers for the instance variables.
-
#options ⇒ Object
Set readers for the instance variables.
Instance Method Summary collapse
-
#constraint ⇒ Constraint
Get the constraint from the metadata once.
-
#deserialize(object) ⇒ Object
Deserialize this field from the type stored in MongoDB to the type defined on the model.
-
#eval_default(doc) ⇒ Object
Evaluate the default value and return it.
-
#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 BSON::ObjectId?.
-
#serialize(object) ⇒ Object
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
-
#type ⇒ Class
Get the type of this field - inferred from the class name.
-
#versioned? ⇒ true, false
Is this field included in versioned attributes?.
Instance Attribute Details
#default_val ⇒ Object
Set readers for the instance variables.
38 39 40 |
# File 'lib/mongoid/fields/serializable.rb', line 38 def default_val @default_val end |
#label ⇒ Object
Set readers for the instance variables.
38 39 40 |
# File 'lib/mongoid/fields/serializable.rb', line 38 def label @label end |
#localize ⇒ Object
Set readers for the instance variables.
38 39 40 |
# File 'lib/mongoid/fields/serializable.rb', line 38 def localize @localize end |
#name ⇒ Object
Set readers for the instance variables.
38 39 40 |
# File 'lib/mongoid/fields/serializable.rb', line 38 def name @name end |
#options ⇒ Object
Set readers for the instance variables.
38 39 40 |
# File 'lib/mongoid/fields/serializable.rb', line 38 def @options end |
Instance Method Details
#constraint ⇒ Constraint
Get the constraint from the metadata once.
48 49 50 |
# File 'lib/mongoid/fields/serializable.rb', line 48 def constraint @constraint ||= .constraint end |
#deserialize(object) ⇒ Object
Deserialize this field from the type stored in MongoDB to the type defined on the model
63 |
# File 'lib/mongoid/fields/serializable.rb', line 63 def deserialize(object); object; end |
#eval_default(doc) ⇒ Object
Evaluate the default value and return it. Will handle the serialization, proc calls, and duplication if necessary.
76 77 78 79 80 81 82 |
# File 'lib/mongoid/fields/serializable.rb', line 76 def eval_default(doc) if default_val.respond_to?(:call) serialize(doc.instance_exec(&default_val)) else serialize(default_val.duplicable? ? default_val.dup : default_val) end end |
#localized? ⇒ true, false
Is the field localized or not?
92 93 94 |
# File 'lib/mongoid/fields/serializable.rb', line 92 def localized? !!@localize end |
#metadata ⇒ Metadata
Get the metadata for the field if its a foreign key.
104 105 106 |
# File 'lib/mongoid/fields/serializable.rb', line 104 def @metadata ||= [:metadata] end |
#object_id_field? ⇒ true, false
Is the field a BSON::ObjectId?
116 117 118 |
# File 'lib/mongoid/fields/serializable.rb', line 116 def object_id_field? @object_id_field ||= (type == BSON::ObjectId) end |
#serialize(object) ⇒ Object
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
131 |
# File 'lib/mongoid/fields/serializable.rb', line 131 def serialize(object); object; end |
#type ⇒ Class
Get the type of this field - inferred from the class name.
141 142 143 |
# File 'lib/mongoid/fields/serializable.rb', line 141 def type @type ||= [:type] || Object end |
#versioned? ⇒ true, false
Is this field included in versioned attributes?
153 154 155 |
# File 'lib/mongoid/fields/serializable.rb', line 153 def versioned? @versioned ||= ([:versioned].nil? ? true : [:versioned]) end |