Class: MongoDbUtils::Model::Db

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo-db-utils/models/db.rb

Overview

A Db stored in the config

Direct Known Subclasses

ReplicaSetDb

Constant Summary collapse

URI_NO_USER =
/mongodb:\/\/(.*)\/(.*$)/
URI_USER =
/mongodb:\/\/(.*):(.*)@(.*)\/(.*$)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Db

Returns a new instance of Db.



29
30
31
32
33
# File 'lib/mongo-db-utils/models/db.rb', line 29

def initialize(uri)
  @uri = uri

  host_port
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/mongo-db-utils/models/db.rb', line 27

def name
  @name
end

#passwordObject (readonly)

Returns the value of attribute password.



27
28
29
# File 'lib/mongo-db-utils/models/db.rb', line 27

def password
  @password
end

#uriObject (readonly)

Returns the value of attribute uri.



27
28
29
# File 'lib/mongo-db-utils/models/db.rb', line 27

def uri
  @uri
end

#usernameObject (readonly)

Returns the value of attribute username.



27
28
29
# File 'lib/mongo-db-utils/models/db.rb', line 27

def username
  @username
end

Instance Method Details

#<=>(other) ⇒ Object



63
64
65
# File 'lib/mongo-db-utils/models/db.rb', line 63

def <=>(other)
  self.to_s <=> other.to_s
end

#authentication_required?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/mongo-db-utils/models/db.rb', line 35

def authentication_required?
  has?(self.username) && has?(self.password)
end

#hostObject



39
40
41
# File 'lib/mongo-db-utils/models/db.rb', line 39

def host
  host_and_port[:host]
end

#host_portObject



67
# File 'lib/mongo-db-utils/models/db.rb', line 67

def host_port; bits[:host_port]; end

#portObject



43
44
45
# File 'lib/mongo-db-utils/models/db.rb', line 43

def port
  host_and_port[:port]
end

#to_host_sObject

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



51
52
53
# File 'lib/mongo-db-utils/models/db.rb', line 51

def to_host_s
  "#{host_port}"
end

#to_sObject



59
60
61
# File 'lib/mongo-db-utils/models/db.rb', line 59

def to_s
  "[SingleDb-(#{to_host_s}/#{name})]"
end

#to_s_simpleObject



55
56
57
# File 'lib/mongo-db-utils/models/db.rb', line 55

def to_s_simple
  "#{name} on #{host_port} - (#{username}:#{password})"
end