Class: MongoODM::Config
- Inherits:
-
Object
- Object
- MongoODM::Config
- Defined in:
- lib/mongo_odm/config.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
-
#host ⇒ Object
Returns the value of attribute host.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#password ⇒ Object
Returns the value of attribute password.
-
#pool_size ⇒ Object
Returns the value of attribute pool_size.
-
#port ⇒ Object
Returns the value of attribute port.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #connection ⇒ Object
- #from_hash(opts) ⇒ Object
-
#initialize(opts = {}) ⇒ Config
constructor
A new instance of Config.
- #uri=(uri) ⇒ Object
Constructor Details
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
5 6 7 |
# File 'lib/mongo_odm/config.rb', line 5 def database @database end |
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/mongo_odm/config.rb', line 5 def host @host end |
#logger ⇒ Object
Returns the value of attribute logger.
6 7 8 |
# File 'lib/mongo_odm/config.rb', line 6 def logger @logger end |
#password ⇒ Object
Returns the value of attribute password.
5 6 7 |
# File 'lib/mongo_odm/config.rb', line 5 def password @password end |
#pool_size ⇒ Object
Returns the value of attribute pool_size.
6 7 8 |
# File 'lib/mongo_odm/config.rb', line 6 def pool_size @pool_size end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/mongo_odm/config.rb', line 5 def port @port end |
#username ⇒ Object
Returns the value of attribute username.
5 6 7 |
# File 'lib/mongo_odm/config.rb', line 5 def username @username end |
Instance Method Details
#connection ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/mongo_odm/config.rb', line 37 def connection opts = { :logger => self.logger, :pool_size => self.pool_size } Mongo::Connection.new(self.host, self.port, opts).tap do |conn| if self.username || self.password conn.add_auth(self.database, self.username, self.password) conn.apply_saved_authentication end end end |
#from_hash(opts) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mongo_odm/config.rb', line 23 def from_hash(opts) opts = opts.dup.symbolize_keys! if opts[:uri].present? self.uri = opts[:uri] else @database, @host, @port, @username, @password = opts.values_at(:database, :host, :port, :username, :password) @port &&= Integer(@port) end @logger ||= opts[:logger] @pool_size ||= opts[:pool_size] end |
#uri=(uri) ⇒ Object
17 18 19 20 21 |
# File 'lib/mongo_odm/config.rb', line 17 def uri=(uri) uri = URI.parse(uri) unless URI === uri @database = uri.path.to_s.sub('/', '') @host, @port, @username, @password = uri.host, uri.port, uri.user, uri.password end |