Class: MongoDoc::Associations::DocumentProxy

Inherits:
Object
  • Object
show all
Includes:
ProxyBase
Defined in:
lib/mongo_doc/associations/document_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ProxyBase

included, #initialize, is_document?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/mongo_doc/associations/document_proxy.rb', line 52

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

#documentObject

Returns the value of attribute document.



6
7
8
# File 'lib/mongo_doc/associations/document_proxy.rb', line 6

def document
  @document
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/mongo_doc/associations/document_proxy.rb', line 24

def ==(other)
  if self.class === other
    document == other.document
  else
    document == other
  end
end

#_root=(value) ⇒ Object



19
20
21
22
# File 'lib/mongo_doc/associations/document_proxy.rb', line 19

def _root=(value)
  @_root = value
  document._root = value if ProxyBase.is_document?(document)
end

#build(attrs) ⇒ Object



32
33
34
35
# File 'lib/mongo_doc/associations/document_proxy.rb', line 32

def build(attrs)
  item = _assoc_class.new(attrs)
  self.document = item
end

#valid?Boolean

Returns:



42
43
44
45
46
47
48
# File 'lib/mongo_doc/associations/document_proxy.rb', line 42

def valid?
  if ProxyBase.is_document?(document)
    document.valid?
  else
    true
  end
end