Class: MongoDbUtils::Model::Db
- Inherits:
-
Object
- Object
- MongoDbUtils::Model::Db
- Defined in:
- lib/mongo-db-utils/models/db.rb
Overview
A Db stored in the config
Direct Known Subclasses
Constant Summary collapse
- URI_NO_USER =
/mongodb:\/\/(.*)\/(.*$)/- URI_USER =
/mongodb:\/\/(.*):(.*)@(.*)\/(.*$)/
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#password ⇒ Object
Returns the value of attribute password.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #authentication_required? ⇒ Boolean
-
#initialize(uri) ⇒ Db
constructor
A new instance of Db.
-
#to_host_s ⇒ Object
Return the host string in a format that is compatable with mongo binary tools See: docs.mongodb.org/manual/reference/program/mongodump/#cmdoption-mongodump–host.
- #to_s ⇒ Object
- #to_s_simple ⇒ Object
Constructor Details
#initialize(uri) ⇒ Db
Returns a new instance of Db.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mongo-db-utils/models/db.rb', line 12 def initialize(uri) user,pwd,host_port,db = nil if( uri.match(URI_USER)) match, user, pwd, host_port, name = *uri.match(URI_USER) elsif(uri.match(URI_NO_USER)) match, host_port, name = *uri.match(URI_NO_USER) user = "" pwd = "" end raise "can't parse uri" if( host_port.nil? || name.nil? ) @host_port = host_port @name = name @username = user @password = pwd @uri = uri end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/mongo-db-utils/models/db.rb', line 10 def name @name end |
#password ⇒ Object
Returns the value of attribute password.
10 11 12 |
# File 'lib/mongo-db-utils/models/db.rb', line 10 def password @password end |
#uri ⇒ Object
Returns the value of attribute uri.
10 11 12 |
# File 'lib/mongo-db-utils/models/db.rb', line 10 def uri @uri end |
#username ⇒ Object
Returns the value of attribute username.
10 11 12 |
# File 'lib/mongo-db-utils/models/db.rb', line 10 def username @username end |
Instance Method Details
#<=>(other) ⇒ Object
50 51 52 |
# File 'lib/mongo-db-utils/models/db.rb', line 50 def <=>(other) self.to_s <=> other.to_s end |
#authentication_required? ⇒ Boolean
32 33 34 |
# File 'lib/mongo-db-utils/models/db.rb', line 32 def authentication_required? has?(self.username) && has?(self.password) end |
#to_host_s ⇒ Object
Return the host string in a format that is compatable with mongo binary tools See: docs.mongodb.org/manual/reference/program/mongodump/#cmdoption-mongodump–host
38 39 40 |
# File 'lib/mongo-db-utils/models/db.rb', line 38 def to_host_s "#{@host_port}" end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/mongo-db-utils/models/db.rb', line 46 def to_s "[SingleDb-(#{to_host_s}/#{name})]" end |
#to_s_simple ⇒ Object
42 43 44 |
# File 'lib/mongo-db-utils/models/db.rb', line 42 def to_s_simple "#{@name} on #{@host_port} - (#{@username}:#{@password})" end |