Sha256: 010dc65951c0997ce49f75f228816ffadc1b04ea67dd4b0251651cd14a181b4b

Contents?: true

Size: 727 Bytes

Versions: 1

Compression:

Stored size: 727 Bytes

Contents

require "easy-settings/version"
require "easy-settings/struct"
require "easy-settings/env_source"
require "easy-settings/path_source"
require "easy-settings/yaml_source"

class EasySettings
  delegate :respond_to?, to: :@data

  def initialize(sources:, fail_on_missing: true)
    @sources = sources
    @fail_on_missing = fail_on_missing
    reload!
  end

  def reload!
    config = {}
    @sources.each do |source|
      data = source.load
      config.deep_merge!(data)
    end
    @data = EasySettings::Struct.import(config)
  end

  def method_missing(method_name, *args)
    @data.send(method_name, *args)
  rescue EasySettings::Struct::UnknownPropertyError => e
    return unless @fail_on_missing
    raise e
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
easy-settings-1.0.0 lib/easy-settings.rb