Module: Pgbus::ConfigLoader

Defined in:
lib/pgbus/config_loader.rb

Class Method Summary collapse

Class Method Details

.apply(hash) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/pgbus/config_loader.rb', line 18

def apply(hash)
  config = Pgbus.configuration
  hash.each do |key, value|
    setter = :"#{key}="
    config.public_send(setter, value) if config.respond_to?(setter)
  end
  config
end

.load(path, env: nil) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/pgbus/config_loader.rb', line 10

def load(path, env: nil)
  env ||= (defined?(Rails) && Rails.respond_to?(:env) && Rails.env) || ENV.fetch("PGBUS_ENV", "development")
  raw = File.read(path)
  parsed = YAML.safe_load(ERB.new(raw).result, permitted_classes: [Symbol], aliases: true)
  config_hash = parsed.fetch(env, parsed)
  apply(config_hash)
end