Class: NetSystem::MongoClient

Inherits:
Client show all
Defined in:
lib/net_system/subsystems/database/clients/mongo_client.rb

Instance Attribute Summary collapse

Attributes inherited from Liza::Controller

#menv

Instance Method Summary collapse

Methods inherited from Liza::Controller

#`, `, attr_accessor, attr_reader, attr_writer, #attrs, box, #box, call, color, division, division!, division?, inherited, menv_accessor, menv_reader, menv_writer, on_connected, panel, #panel, plural, require, requirements, sh, #sh, singular, subsystem, subsystem!, subsystem?, subsystem_token, token

Methods inherited from Liza::Unit

_erbs_for, #add, add, cl, #cl, class_methods_defined, const_added, const_missing, constants_defined, define_error, descendants_select, division, erbs_available, erbs_defined, erbs_for, errors, #fetch, fetch, get, #get, instance_methods_defined, log, #log, log?, #log?, #log_array, log_array, log_hash, #log_hash, #log_level, log_level, #log_level?, log_level?, log_levels, #log_levels, #log_render_convert, #log_render_format, #log_render_in, #log_render_out, method_added, methods_defined, namespace, part, raise_error, #raise_error, reload!, #reload!, #render, #render!, #render_stack, renderable_formats_for, renderable_names, section, sections, #set, set, #settings, settings, singleton_method_added, sleep, #sleep, stick, #stick, sticks, #sticks, subclasses_select, subunits, system, #system, system?, test_class, time_diff, #time_diff

Constructor Details

#initialize(hash = {}) ⇒ MongoClient



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/net_system/subsystems/database/clients/mongo_client.rb', line 6

def initialize hash={}
  self.class.call({})
  t = Time.now
  hash = NetBox[:client].get(:mongo_hash) if hash.empty?
  host = hash[:host]
  port = hash[:port]
  username = hash[:username]
  password = hash[:password]
  protocol = hash[:protocol] || "mongodb"
  database = hash[:database]

  uri =
    if password.to_s.size.positive?
      "#{protocol}://#{username}:#{password}@#{host}:#{port}/#{database}"
    else
      "#{protocol}://#{host}:#{port}/#{database}"
    end

  @conn = Mongo::Client.new(uri)
ensure
  log "#{t.diff}s | Connecting to #{hash}"
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



29
30
31
# File 'lib/net_system/subsystems/database/clients/mongo_client.rb', line 29

def conn
  @conn
end

Instance Method Details

#call(args) ⇒ Object



31
32
33
34
35
36
# File 'lib/net_system/subsystems/database/clients/mongo_client.rb', line 31

def call args
  t = Time.now
  raise NotImplementedError
ensure
  log "#{t.diff}s | #{cmd_name} | #{args}"
end

#nowObject



38
39
40
41
42
43
44
45
# File 'lib/net_system/subsystems/database/clients/mongo_client.rb', line 38

def now
  t0 = Time.now
  server_status = @conn.database.command(serverStatus: 1)
  t = server_status.first['localTime']
  Time.at t.to_i
ensure
  log "#{t0.diff}s | now | []"
end