Class: InfluxdbSetup::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/influxdb_setup/config.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: self.class.config, logger: Logger.new(STDOUT)) ⇒ Config



17
18
19
20
# File 'lib/influxdb_setup/config.rb', line 17

def initialize(config: self.class.config, logger: Logger.new(STDOUT))
  @config = config
  @logger = logger
end

Class Attribute Details

.configObject



11
12
13
# File 'lib/influxdb_setup/config.rb', line 11

def self.config
  @config ||= YAML.load(ERB.new(File.read("config/influxdb.yml")).result)[env]
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



15
16
17
# File 'lib/influxdb_setup/config.rb', line 15

def logger
  @logger
end

Instance Method Details

#build_client(database = "", options = {}) ⇒ Object



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

def build_client(database = "", options = {})
  InfluxDB::Client.new(database,
                      {
                        username: "root",
                        password: "root",
                        hosts:    @config["hosts"],
                        port:     @config.fetch("port", 8086),
                        async:    false,
                        use_ssl:  @config.fetch("use_ssl", false),
                        retry:    false,
                      }.merge(options))
end

#db_nameObject



26
27
28
# File 'lib/influxdb_setup/config.rb', line 26

def db_name
  @config['db_name']
end

#enabled?Boolean



30
31
32
# File 'lib/influxdb_setup/config.rb', line 30

def enabled?
  @config['enabled']
end

#envObject



22
23
24
# File 'lib/influxdb_setup/config.rb', line 22

def env
  defined?(Rails) ? Rails.env : ENV.fetch('RAILS_ENV', 'development')
end

#passwordObject



38
39
40
# File 'lib/influxdb_setup/config.rb', line 38

def password
  @config['password']
end

#usernameObject



34
35
36
# File 'lib/influxdb_setup/config.rb', line 34

def username
  @config['username']
end