Class: MongoMapper::Plugins::Embeddable::EmbeddableDocument
- Inherits:
-
Object
- Object
- MongoMapper::Plugins::Embeddable::EmbeddableDocument
show all
- Includes:
- EmbeddedDocument
- Defined in:
- lib/mm-embeddable.rb
Overview
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/mm-embeddable.rb', line 30
def method_missing(*args)
if !@expanded
expand!
@expansion.send(*args)
else
super
end
end
|
Class Attribute Details
.full_class ⇒ Object
21
22
23
|
# File 'lib/mm-embeddable.rb', line 21
def self.full_class
@full_class or raise NotImplementedError, 'This embed has no full class.'
end
|
Class Method Details
.from_full(full_document) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/mm-embeddable.rb', line 13
def self.from_full(full_document)
d = self.new
keys.keys.each do |k|
d.send("#{k}=".to_sym, full_document.send(k.to_sym))
end
d
end
|
.to_mongo(instance) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/mm-embeddable.rb', line 39
def self.to_mongo(instance)
case instance
when full_class
from_full(instance).to_mongo
else
instance.to_mongo
end
end
|
Instance Method Details
#expand! ⇒ Object
25
26
27
28
|
# File 'lib/mm-embeddable.rb', line 25
def expand!
@expanded = true
@expansion = self.class.full_class.find(self.id)
end
|