Module: Mongoid::Clients::ClassMethods
- Defined in:
- lib/mongoid/clients.rb
Instance Method Summary collapse
-
#collection ⇒ Mongo::Collection
Get the collection for this model from the client.
-
#mongo_client ⇒ Mongo::Client
Get the client for this model.
Instance Method Details
#collection ⇒ Mongo::Collection
Get the collection for this model from the client. Will check for an overridden collection name from the store_in macro or the collection with a pluralized model name.
134 135 136 |
# File 'lib/mongoid/clients.rb', line 134 def collection mongo_client[collection_name] end |
#mongo_client ⇒ Mongo::Client
Get the client for this model. This is determined in the following order:
1. Any custom configuration provided by the 'store_in' macro.
2. The 'default' client as provided in the mongoid.yml
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/mongoid/clients.rb', line 113 def mongo_client return if client = Clients.with_name(client_name) opts = self. ? self..dup : {} if defined?(Mongo::Client::VALID_OPTIONS) opts.reject! { |k, v| !Mongo::Client::VALID_OPTIONS.include?(k.to_sym) } end opts.merge!(database: database_name) unless client.database.name.to_sym == database_name.to_sym client.with(opts) end |