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, opts = {}) ⇒ YAML
constructor
A new instance of YAML.
- #lookup_path(setting_path, *_) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(file, opts = {}) ⇒ YAML
Returns a new instance of YAML.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/configurate/provider/yaml.rb', line 14 def initialize file, opts = {} @settings = {} required = opts.delete(:required) { true } @settings = ::YAML.load_file(file) namespace = opts.delete(:namespace) 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 $stderr.puts "WARNING: Configuration file #{file} not found, ensure it's present" raise e if required end |
Instance Method Details
#lookup_path(setting_path, *_) ⇒ Object
33 34 35 |
# File 'lib/configurate/provider/yaml.rb', line 33 def lookup_path setting_path, *_ Provider.lookup_in_hash(setting_path, @settings) end |