Module: MongoMapper::EmbeddedDocument::ClassMethods
- Defined in:
- lib/mongo_mapper/embedded_document.rb
Instance Method Summary collapse
- #embeddable? ⇒ Boolean
- #from_mongo(value) ⇒ Object
- #inherited(subclass) ⇒ Object
- #key(*args) ⇒ Object
- #keys ⇒ Object
- #logger ⇒ Object
- #object_id_key?(name) ⇒ Boolean
- #parent_model ⇒ Object
- #subclasses ⇒ Object
- #to_mongo(instance) ⇒ Object
- #using_object_id? ⇒ Boolean
Instance Method Details
#embeddable? ⇒ Boolean
67 68 69 |
# File 'lib/mongo_mapper/embedded_document.rb', line 67 def !self.ancestors.include?(Document) end |
#from_mongo(value) ⇒ Object
82 83 84 85 |
# File 'lib/mongo_mapper/embedded_document.rb', line 82 def from_mongo(value) return nil if value.nil? value.is_a?(self) ? value : initialize_doc(value) end |
#inherited(subclass) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/mongo_mapper/embedded_document.rb', line 27 def inherited(subclass) unless subclass. subclass.set_collection_name(collection_name) end (@subclasses ||= []) << subclass end |
#key(*args) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mongo_mapper/embedded_document.rb', line 47 def key(*args) key = Key.new(*args) keys[key.name] = key create_accessors_for(key) create_key_in_subclasses(*args) create_validations_for(key) key end |
#keys ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/mongo_mapper/embedded_document.rb', line 39 def keys @keys ||= if parent = parent_model parent.keys.dup else HashWithIndifferentAccess.new end end |
#logger ⇒ Object
23 24 25 |
# File 'lib/mongo_mapper/embedded_document.rb', line 23 def logger MongoMapper.logger end |
#object_id_key?(name) ⇒ Boolean
62 63 64 65 |
# File 'lib/mongo_mapper/embedded_document.rb', line 62 def object_id_key?(name) key = keys[name.to_s] key && key.type == ObjectId end |
#parent_model ⇒ Object
71 72 73 74 75 |
# File 'lib/mongo_mapper/embedded_document.rb', line 71 def parent_model (ancestors - [self,EmbeddedDocument]).find do |parent_class| parent_class.ancestors.include?(EmbeddedDocument) end end |
#subclasses ⇒ Object
35 36 37 |
# File 'lib/mongo_mapper/embedded_document.rb', line 35 def subclasses @subclasses end |
#to_mongo(instance) ⇒ Object
77 78 79 80 |
# File 'lib/mongo_mapper/embedded_document.rb', line 77 def to_mongo(instance) return nil if instance.nil? instance.to_mongo end |
#using_object_id? ⇒ Boolean
58 59 60 |
# File 'lib/mongo_mapper/embedded_document.rb', line 58 def using_object_id? object_id_key?(:_id) end |