Class: MongoDbUtils::Model::ReplicaSetDb

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

Constant Summary

Constants inherited from Db

Db::URI_NO_USER, Db::URI_USER

Instance Attribute Summary collapse

Attributes inherited from Db

#name, #password, #uri, #username

Instance Method Summary collapse

Methods inherited from Db

#<=>, #authentication_required?, #host_port, #to_s_simple

Constructor Details

#initialize(uri, name) ⇒ ReplicaSetDb

Returns a new instance of ReplicaSetDb.



112
113
114
115
# File 'lib/mongo-db-utils/models/db.rb', line 112

def initialize(uri, name)
  super(uri)
  @set_name = name
end

Instance Attribute Details

#set_nameObject (readonly)

Returns the value of attribute set_name.



111
112
113
# File 'lib/mongo-db-utils/models/db.rb', line 111

def set_name
  @set_name
end

Instance Method Details

#hostObject

Block usage of this method from the super



124
125
126
# File 'lib/mongo-db-utils/models/db.rb', line 124

def host
  raise "'host' is not a valid method for a ReplicaSetDb - use 'hosts' instead."
end

#hostsObject

Return an array of host:port strings



119
120
121
# File 'lib/mongo-db-utils/models/db.rb', line 119

def hosts
  host_port.split(",")
end

#portObject

Block usage of this method from the super



129
130
131
# File 'lib/mongo-db-utils/models/db.rb', line 129

def port
  raise "'port' is not a valid method for a ReplicaSetDb - use 'hosts' instead."
end

#to_host_sObject

Note: we override this to provide a replica set format



134
135
136
# File 'lib/mongo-db-utils/models/db.rb', line 134

def to_host_s
  "#{@set_name}/#{host_port}"
end

#to_sObject



138
139
140
# File 'lib/mongo-db-utils/models/db.rb', line 138

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