Class: Comet::MongoDBConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/comet/models/mongo_dbconnection.rb

Overview

MongoDBConnection is a typed class wrapper around the underlying Comet Server API data structure.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMongoDBConnection

Returns a new instance of MongoDBConnection.



77
78
79
# File 'lib/comet/models/mongo_dbconnection.rb', line 77

def initialize
  clear
end

Instance Attribute Details

#allow_invalid_certificateObject

Returns the value of attribute allow_invalid_certificate.



63
64
65
# File 'lib/comet/models/mongo_dbconnection.rb', line 63

def allow_invalid_certificate
  @allow_invalid_certificate
end

#allow_invalid_hostnameObject

Returns the value of attribute allow_invalid_hostname.



66
67
68
# File 'lib/comet/models/mongo_dbconnection.rb', line 66

def allow_invalid_hostname
  @allow_invalid_hostname
end

#authentication_dbObject

Returns the value of attribute authentication_db.



30
31
32
# File 'lib/comet/models/mongo_dbconnection.rb', line 30

def authentication_db
  @authentication_db
end

#client_sslpempathObject

Returns the value of attribute client_sslpempath.



54
55
56
# File 'lib/comet/models/mongo_dbconnection.rb', line 54

def client_sslpempath
  @client_sslpempath
end

#mongo_shell_pathObject

Returns the value of attribute mongo_shell_path.



33
34
35
# File 'lib/comet/models/mongo_dbconnection.rb', line 33

def mongo_shell_path
  @mongo_shell_path
end

#mongodump_pathObject

Returns the value of attribute mongodump_path.



36
37
38
# File 'lib/comet/models/mongo_dbconnection.rb', line 36

def mongodump_path
  @mongodump_path
end

#passwordObject

Returns the value of attribute password.



27
28
29
# File 'lib/comet/models/mongo_dbconnection.rb', line 27

def password
  @password
end

#portObject

Returns the value of attribute port.



21
22
23
# File 'lib/comet/models/mongo_dbconnection.rb', line 21

def port
  @port
end

#read_preferenceObject

Returns the value of attribute read_preference.



39
40
41
# File 'lib/comet/models/mongo_dbconnection.rb', line 39

def read_preference
  @read_preference
end

#replica_membersObject

Returns the value of attribute replica_members.



48
49
50
# File 'lib/comet/models/mongo_dbconnection.rb', line 48

def replica_members
  @replica_members
end

#replica_nameObject

Returns the value of attribute replica_name.



45
46
47
# File 'lib/comet/models/mongo_dbconnection.rb', line 45

def replica_name
  @replica_name
end

#serverObject

Returns the value of attribute server.



18
19
20
# File 'lib/comet/models/mongo_dbconnection.rb', line 18

def server
  @server
end

#server_sslpempathObject

Returns the value of attribute server_sslpempath.



57
58
59
# File 'lib/comet/models/mongo_dbconnection.rb', line 57

def server_sslpempath
  @server_sslpempath
end

#sshconnectionObject

Returns the value of attribute sshconnection.



72
73
74
# File 'lib/comet/models/mongo_dbconnection.rb', line 72

def sshconnection
  @sshconnection
end

#sslclient_key_passwordObject

Returns the value of attribute sslclient_key_password.



60
61
62
# File 'lib/comet/models/mongo_dbconnection.rb', line 60

def sslclient_key_password
  @sslclient_key_password
end

#unknown_json_fieldsObject

Returns the value of attribute unknown_json_fields.



75
76
77
# File 'lib/comet/models/mongo_dbconnection.rb', line 75

def unknown_json_fields
  @unknown_json_fields
end

#use_replicaObject

Returns the value of attribute use_replica.



42
43
44
# File 'lib/comet/models/mongo_dbconnection.rb', line 42

def use_replica
  @use_replica
end

#use_sshObject

Returns the value of attribute use_ssh.



69
70
71
# File 'lib/comet/models/mongo_dbconnection.rb', line 69

def use_ssh
  @use_ssh
end

#use_sslObject

Returns the value of attribute use_ssl.



51
52
53
# File 'lib/comet/models/mongo_dbconnection.rb', line 51

def use_ssl
  @use_ssl
end

#usernameObject

Returns the value of attribute username.



24
25
26
# File 'lib/comet/models/mongo_dbconnection.rb', line 24

def username
  @username
end

Instance Method Details

#clearObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/comet/models/mongo_dbconnection.rb', line 81

def clear
  @server = ''
  @port = 0
  @username = ''
  @password = ''
  @authentication_db = ''
  @mongo_shell_path = ''
  @mongodump_path = ''
  @read_preference = ''
  @replica_name = ''
  @replica_members = []
  @client_sslpempath = ''
  @server_sslpempath = ''
  @sslclient_key_password = ''
  @sshconnection = Comet::SSHConnection.new
  @unknown_json_fields = {}
end

#from_hash(obj) ⇒ Object

Parameters:

  • obj (Hash)

    The complete object as a Ruby hash

Raises:

  • (TypeError)


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/comet/models/mongo_dbconnection.rb', line 107

def from_hash(obj)
  raise TypeError, "'obj' expected Hash, got #{obj.class}" unless obj.is_a? Hash

  obj.each do |k, v|
    case k
    when 'Server'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @server = v
    when 'Port'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @port = v
    when 'Username'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @username = v
    when 'Password'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @password = v
    when 'AuthenticationDB'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @authentication_db = v
    when 'MongoShellPath'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @mongo_shell_path = v
    when 'MongodumpPath'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @mongodump_path = v
    when 'ReadPreference'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @read_preference = v
    when 'UseReplica'
      @use_replica = v
    when 'ReplicaName'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @replica_name = v
    when 'ReplicaMembers'
      if v.nil?
        @replica_members = []
      else
        @replica_members = Array.new(v.length)
        v.each_with_index do |v1, i1|
          raise TypeError, "'v1' expected String, got #{v1.class}" unless v1.is_a? String

          @replica_members[i1] = v1
        end
      end
    when 'UseSSL'
      @use_ssl = v
    when 'ClientSSLPEMPath'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @client_sslpempath = v
    when 'ServerSSLPEMPath'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @server_sslpempath = v
    when 'SSLClientKeyPassword'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @sslclient_key_password = v
    when 'AllowInvalidCertificate'
      @allow_invalid_certificate = v
    when 'AllowInvalidHostname'
      @allow_invalid_hostname = v
    when 'UseSSH'
      @use_ssh = v
    when 'SSHConnection'
      @sshconnection = Comet::SSHConnection.new
      @sshconnection.from_hash(v)
    else
      @unknown_json_fields[k] = v
    end
  end
end

#from_json(json_string) ⇒ Object

Parameters:

  • json_string (String)

    The complete object in JSON format

Raises:

  • (TypeError)


100
101
102
103
104
# File 'lib/comet/models/mongo_dbconnection.rb', line 100

def from_json(json_string)
  raise TypeError, "'json_string' expected String, got #{json_string.class}" unless json_string.is_a? String

  from_hash(JSON.parse(json_string))
end

#to_hHash

Returns The complete object as a Ruby hash.

Returns:

  • (Hash)

    The complete object as a Ruby hash



221
222
223
# File 'lib/comet/models/mongo_dbconnection.rb', line 221

def to_h
  to_hash
end

#to_hashHash

Returns The complete object as a Ruby hash.

Returns:

  • (Hash)

    The complete object as a Ruby hash



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/comet/models/mongo_dbconnection.rb', line 191

def to_hash
  ret = {}
  ret['Server'] = @server
  ret['Port'] = @port
  ret['Username'] = @username
  ret['Password'] = @password
  ret['AuthenticationDB'] = @authentication_db
  ret['MongoShellPath'] = @mongo_shell_path
  ret['MongodumpPath'] = @mongodump_path
  ret['ReadPreference'] = @read_preference
  ret['UseReplica'] = @use_replica
  ret['ReplicaName'] = @replica_name
  ret['ReplicaMembers'] = @replica_members
  ret['UseSSL'] = @use_ssl
  ret['ClientSSLPEMPath'] = @client_sslpempath
  ret['ServerSSLPEMPath'] = @server_sslpempath
  ret['SSLClientKeyPassword'] = @sslclient_key_password
  ret['AllowInvalidCertificate'] = @allow_invalid_certificate
  ret['AllowInvalidHostname'] = @allow_invalid_hostname
  ret['UseSSH'] = @use_ssh
  unless @sshconnection.nil?
    ret['SSHConnection'] = @sshconnection
  end
  @unknown_json_fields.each do |k, v|
    ret[k] = v
  end
  ret
end

#to_json(options = {}) ⇒ String

Returns The complete object as a JSON string.

Returns:

  • (String)

    The complete object as a JSON string



226
227
228
# File 'lib/comet/models/mongo_dbconnection.rb', line 226

def to_json(options = {})
  to_hash.to_json(options)
end