Class: MongodbLogger::ServerConfig

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

Class Method Summary (collapse)

Class Method Details

+ (Object) collection



40
41
42
# File 'lib/mongodb_logger/server_config.rb', line 40

def collection
  @collection
end

+ (Object) db



36
37
38
# File 'lib/mongodb_logger/server_config.rb', line 36

def db
  @db
end

+ (Object) get_config



32
33
34
# File 'lib/mongodb_logger/server_config.rb', line 32

def get_config
  @db_configuration
end

+ (Object) set_config(config_path)



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mongodb_logger/server_config.rb', line 9

def set_config(config_path)
  if File.file?(config_path)
    config_file = File.new(config_path)
    config = YAML.load(ERB.new(config_file.read).result)
  else
    raise "Config file not found"
  end
  
  @db_configuration = {
    'host' => 'localhost',
    'port' => 27017}.merge(config)
  @db_configuration["collection"] ||= "production_log"
  @db = Mongo::Connection.new(@db_configuration['host'],
                              @db_configuration['port'],
                              :auto_reconnect => true).db(@db_configuration['database'])

  if @db_configuration['username'] && @db_configuration['password']
    @authenticated = @db.authenticate(@db_configuration['username'],
                                                    @db_configuration['password'])
  end
  @collection = @db[@db_configuration["collection"]]
end