Class: InfluxdbSetup::Config

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Config.



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

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

Class Attribute Details

.configObject



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

def self.config
  config_file = ENV.fetch('INFLUXDB_CONFIG_FILE', 'config/influxdb.yml')
  @config ||= YAML.load(ERB.new(File.read(config_file)).result)[env]
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



20
21
22
# File 'lib/influxdb_setup/config.rb', line 20

def logger
  @logger
end

Class Method Details

.envObject



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

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

Instance Method Details

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



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/influxdb_setup/config.rb', line 47

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

#db_nameObject



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

def db_name
  @config['db_name']
end

#enabled?Boolean

Returns:

  • (Boolean)


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

def enabled?
  @config['enabled']
end

#passwordObject



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

def password
  @config['password']
end

#retention_policiesObject



43
44
45
# File 'lib/influxdb_setup/config.rb', line 43

def retention_policies
  @config['retention_policies']
end

#usernameObject



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

def username
  @config['username']
end