Class: Dry::System::Settings::Configuration

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/dry/system/settings.rb

Class Method Summary collapse

Class Method Details

.load(root, env) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dry/system/settings.rb', line 40

def self.load(root, env)
  env_data = load_files(root, env)
  attributes = {}
  errors = {}

  schema.each do |key|
    value = ENV.fetch(key.name.to_s.upcase) { env_data[key.name.to_s.upcase] }
    type_check = key.try(value || Undefined)

    attributes[key.name] = value if value
    errors[key] = type_check if type_check.failure?
  end

  raise InvalidSettingsError.new(errors) unless errors.empty?

  new(attributes)
end

.setting(*args) ⇒ Object


36
37
38
# File 'lib/dry/system/settings.rb', line 36

def self.setting(*args)
  attribute(*args)
end