Module: Clickhouse::Rails::Config
- Defined in:
- lib/clickhouse/rails/config.rb
Defined Under Namespace
Classes: ConfigurationNotFound
Constant Summary
collapse
- CLICKHOUSE_ROOT =
File.expand_path(::Rails.root.present? ? ::Rails.root : '.')
- DEFAULT_CONFIG_PATH =
File.join(CLICKHOUSE_ROOT, 'config', 'clickhouse.yml')
Class Method Summary
collapse
Class Method Details
.config_mapper(source) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/clickhouse/rails/config.rb', line 24
def self.config_mapper(source)
return nil if source.nil?
{
urls: source['hosts']&.split(','),
username: source['username'],
password: source['password']
}
end
|
.init(config_path = nil) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/clickhouse/rails/config.rb', line 11
def self.init(config_path = nil)
config_path ||= DEFAULT_CONFIG_PATH
exists = config_path && File.exist?(config_path)
unless exists
raise ConfigurationNotFound, "could not find the \"#{config_path}\" configuration file"
end
content = File.read(config_path)
data = defined?(ERB) ? ERB.new(content).result : content
source = YAML.safe_load(data)[defined?(::Rails) ? ::Rails.env : ENV['CLICKHOUSE_ENV']]
config_mapper(source)
end
|