Module: Mongo::DocumentClass
- Defined in:
- lib/mongo/document.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
For other methods on collection(or not), just send to it.
35
36
37
|
# File 'lib/mongo/document.rb', line 35
def method_missing(name, *args)
collection.send(name, *args)
end
|
Instance Method Details
#client ⇒ Object
Also known as:
connection
9
10
11
12
13
14
|
# File 'lib/mongo/document.rb', line 9
def client
if !@client
raise "No connection! You should call Mongo::Document.establish_connection before."
end
@client
end
|
#collection ⇒ Object
17
18
19
|
# File 'lib/mongo/document.rb', line 17
def collection
@collection ||= client[collection_name]
end
|
#collection_name ⇒ Object
21
22
23
|
# File 'lib/mongo/document.rb', line 21
def collection_name
@collection_name ||= name.underscore.pluralize
end
|
#collection_name=(name) ⇒ Object
25
26
27
|
# File 'lib/mongo/document.rb', line 25
def collection_name=(name)
@collection_name = name
end
|
#find(*args) ⇒ Object
A little optimazation for the most frequently-used method.
30
31
32
|
# File 'lib/mongo/document.rb', line 30
def find(*args)
collection.find(*args)
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
39
40
41
|
# File 'lib/mongo/document.rb', line 39
def respond_to_missing?(name, include_private = false)
collection.respond_to?(name, include_private) || super
end
|