Module: MongoMapper::EmbeddedDocument::ClassMethods
- Defined in:
- lib/mongo_mapper/embedded_document.rb
Instance Method Summary collapse
- #embeddable? ⇒ Boolean
- #from_mongo(instance_or_hash) ⇒ Object
- #inherited(subclass) ⇒ Object
- #key(*args) ⇒ Object
- #keys ⇒ Object
- #logger ⇒ Object
- #parent_model ⇒ Object
- #subclasses ⇒ Object
- #to_mongo(instance) ⇒ Object
Instance Method Details
#embeddable? ⇒ Boolean
65 66 67 |
# File 'lib/mongo_mapper/embedded_document.rb', line 65 def !self.ancestors.include?(Document) end |
#from_mongo(instance_or_hash) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/mongo_mapper/embedded_document.rb', line 80 def from_mongo(instance_or_hash) return nil if instance_or_hash.nil? if instance_or_hash.is_a?(self) instance_or_hash else new(instance_or_hash) end end |
#inherited(subclass) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/mongo_mapper/embedded_document.rb', line 29 def inherited(subclass) unless subclass. subclass.set_collection_name(collection_name) end (@subclasses ||= []) << subclass end |
#key(*args) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mongo_mapper/embedded_document.rb', line 49 def key(*args) key = Key.new(*args) if keys[key.name].blank? keys[key.name] = key create_accessors_for(key) create_key_in_subclasses(*args) create_validations_for(key) key end key end |
#keys ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/mongo_mapper/embedded_document.rb', line 41 def keys @keys ||= if parent = parent_model parent.keys.dup else HashWithIndifferentAccess.new end end |
#logger ⇒ Object
25 26 27 |
# File 'lib/mongo_mapper/embedded_document.rb', line 25 def logger MongoMapper.logger end |
#parent_model ⇒ Object
69 70 71 72 73 |
# File 'lib/mongo_mapper/embedded_document.rb', line 69 def parent_model (ancestors - [self,EmbeddedDocument]).find do |parent_class| parent_class.ancestors.include?(EmbeddedDocument) end end |
#subclasses ⇒ Object
37 38 39 |
# File 'lib/mongo_mapper/embedded_document.rb', line 37 def subclasses @subclasses end |
#to_mongo(instance) ⇒ Object
75 76 77 78 |
# File 'lib/mongo_mapper/embedded_document.rb', line 75 def to_mongo(instance) return nil if instance.nil? instance.to_mongo end |