Class: MongoDoc::Associations::DocumentProxy

Inherits:
ProxyBase show all
Defined in:
lib/mongodoc/associations/document_proxy.rb

Instance Attribute Summary collapse

Attributes inherited from ProxyBase

#_parent, #_root, #assoc_class, #assoc_name

Instance Method Summary collapse

Methods inherited from ProxyBase

#_path_to_root, #attach, #initialize

Constructor Details

This class inherits a constructor from MongoDoc::Associations::ProxyBase

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mongodoc/associations/document_proxy.rb', line 40

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.



5
6
7
# File 'lib/mongodoc/associations/document_proxy.rb', line 5

def document
  @document
end

Instance Method Details

#==(other) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/mongodoc/associations/document_proxy.rb', line 12

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

#_root=(root) ⇒ Object



7
8
9
10
# File 'lib/mongodoc/associations/document_proxy.rb', line 7

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

#build(attrs) ⇒ Object



20
21
22
23
# File 'lib/mongodoc/associations/document_proxy.rb', line 20

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

#valid?Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/mongodoc/associations/document_proxy.rb', line 30

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