Class: FeldtRuby::AllMongoDBLoggers

Inherits:
Object
  • Object
show all
Defined in:
lib/feldtruby/mongodb_logger.rb

Overview

This is a class to access the main directory of all MongoDBLogger db’s saved in a mongodb.

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ AllMongoDBLoggers

Returns a new instance of AllMongoDBLoggers.



12
13
14
15
16
17
18
# File 'lib/feldtruby/mongodb_logger.rb', line 12

def initialize host, port
  @host, @port = host, port

  @client = Mongo::MongoClient.new("localhost", 27017)

  @main_db = @client.db("MongoDBLoggers")
end

Instance Method Details

#add_logger(logger) ⇒ Object

Add a logger to the main dir of logger dbs.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/feldtruby/mongodb_logger.rb', line 25

def add_logger(logger)

  db_logger_data = {
    "db_name" => logger.db_name,
    "logger_class" => logger.class.inspect,
    "gem" => "FeldtRuby",
    "gem_version" => FeldtRuby::VERSION,
    "start_time" => logger.start_time
  }

  all_logs.insert db_logger_data

end

#all_log_infosObject



39
40
41
# File 'lib/feldtruby/mongodb_logger.rb', line 39

def all_log_infos
  all_logs.find.to_a
end

#all_logsObject



20
21
22
# File 'lib/feldtruby/mongodb_logger.rb', line 20

def all_logs
  @main_db["all_logs"]
end

#delete_logger_dbs(skipLatestDb = true) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/feldtruby/mongodb_logger.rb', line 43

def delete_logger_dbs skipLatestDb = true

  infos = all_log_infos.sort_by {|i| i["start_time"]}

  if skipLatestDb
    infos = infos - [infos.last]
  end

  infos.each {|i| drop_db_named(i["db_name"])}

end

#drop_db_named(name) ⇒ Object

Drop the logger db with given name.



56
57
58
59
60
61
62
# File 'lib/feldtruby/mongodb_logger.rb', line 56

def drop_db_named name

  @client.drop_database name

  all_logs.remove( {"db_name" => name} )

end