Class: NetSystem::MongoClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Liza::Controller

color, inherited, on_connected

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Constructor Details

#initialize(hash = {}) ⇒ MongoClient



5
6
7
8
9
10
11
12
13
# File 'lib/net_system/sub/database/clients/mongo_client.rb', line 5

def initialize hash={}
  require "mongo"
  t = Time.now
  hash = NetBox[:client].get(:mongo_hash) if hash.empty?
  uri = "mongodb://#{hash[:host]}:#{hash[:port]}/#{hash[:database]}"
  @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.



15
16
17
# File 'lib/net_system/sub/database/clients/mongo_client.rb', line 15

def conn
  @conn
end

Instance Method Details

#call(args) ⇒ Object



17
18
19
20
21
22
# File 'lib/net_system/sub/database/clients/mongo_client.rb', line 17

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

#nowObject



24
25
26
27
28
29
30
31
# File 'lib/net_system/sub/database/clients/mongo_client.rb', line 24

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