Class: MongoDoc::Associations::DocumentProxy
- Inherits:
-
Object
- Object
- MongoDoc::Associations::DocumentProxy
show all
- Includes:
- ProxyBase
- Defined in:
- lib/mongodoc/associations/document_proxy.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from ProxyBase
#_parent=, #_path_to_root, #attach, included, #initialize
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/mongodoc/associations/document_proxy.rb', line 43
def method_missing(method, *args)
unless document.respond_to?(method)
raise NoMethodError, "undefined method `#{method.to_s}' for proxied \"#{document}\":#{document.class.to_s}"
end
if block_given?
document.send(method, *args) { |*block_args| yield(*block_args) }
else
document.send(method, *args)
end
end
|
Instance Attribute Details
Returns the value of attribute document.
6
7
8
|
# File 'lib/mongodoc/associations/document_proxy.rb', line 6
def document
@document
end
|
Instance Method Details
#==(other) ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/mongodoc/associations/document_proxy.rb', line 15
def ==(other)
if self.class === other
document == other.document
else
document == other
end
end
|
#_root=(root) ⇒ Object
10
11
12
13
|
# File 'lib/mongodoc/associations/document_proxy.rb', line 10
def _root=(root)
@_root = root
document._root = root if is_document?(document)
end
|
#build(attrs) ⇒ Object
23
24
25
26
|
# File 'lib/mongodoc/associations/document_proxy.rb', line 23
def build(attrs)
item = assoc_class.new(attrs)
self.document = item
end
|
#valid? ⇒ Boolean
33
34
35
36
37
38
39
|
# File 'lib/mongodoc/associations/document_proxy.rb', line 33
def valid?
if is_document?(document)
document.valid?
else
true
end
end
|