Class: Configurate::Provider::YAML
- Defined in:
- lib/configurate/provider/yaml.rb
Overview
This provider tries to open a YAML file and does nested lookups in it.
Instance Method Summary collapse
-
#initialize(file, namespace: nil, required: true, raise_on_missing: false) ⇒ YAML
constructor
A new instance of YAML.
- #lookup_path(setting_path, *_) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(file, namespace: nil, required: true, raise_on_missing: false) ⇒ YAML
Returns a new instance of YAML.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/configurate/provider/yaml.rb', line 16 def initialize file, namespace: nil, required: true, raise_on_missing: false @raise_on_missing = raise_on_missing @settings = {} @settings = ::YAML.load_file(file) unless namespace.nil? @settings = Provider.lookup_in_hash(SettingPath.new(namespace), @settings) do raise ArgumentError, "Namespace #{namespace} not found in #{file}" if required $stderr.puts "WARNING: Namespace #{namespace} not found in #{file}" nil end end rescue Errno::ENOENT => e warn "WARNING: Configuration file #{file} not found, ensure it's present" raise e if required end |
Instance Method Details
#lookup_path(setting_path, *_) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/configurate/provider/yaml.rb', line 34 def lookup_path setting_path, *_ Provider.lookup_in_hash(setting_path, @settings) { raise MissingSetting.new "#{setting_path} is not a valid setting." if @raise_on_missing nil } end |