Module: Mongo::Document
- Defined in:
- lib/mongo/document.rb
Class Method Summary collapse
- .client ⇒ Object (also: connection)
- .database_file=(file) ⇒ Object
- .descendants ⇒ Object
- .establish_connection(spec) ⇒ Object
- .included(cls) ⇒ Object
Class Method Details
.client ⇒ Object Also known as: connection
57 58 59 |
# File 'lib/mongo/document.rb', line 57 def client @client end |
.database_file=(file) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/mongo/document.rb', line 77 def database_file=(file) config = YAML.load(File.read(file)) env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] spec = config[env] establish_connection(spec) end |
.descendants ⇒ Object
53 54 55 |
# File 'lib/mongo/document.rb', line 53 def descendants @descendants ||= [] end |
.establish_connection(spec) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/mongo/document.rb', line 62 def establish_connection(spec) spec = spec.symbolize_keys hosts_or_uri = nil spec.delete_if do |k, v| if k == :hosts || k == :uri hosts_or_uri = v end end @client = Mongo::Client.new(hosts_or_uri, spec) descendants.each do |model| set_connection(model) end end |
.included(cls) ⇒ Object
47 48 49 50 51 |
# File 'lib/mongo/document.rb', line 47 def included(cls) cls.extend DocumentClass set_connection(cls) descendants << cls end |