Class: Wip::ConfigLoader
- Inherits:
-
Object
- Object
- Wip::ConfigLoader
- Defined in:
- lib/wip/config_loader.rb
Overview
Finds and parses wip.yml, searching parent directories when unset.
Constant Summary collapse
- FILENAME =
'wip.yml'
Instance Method Summary collapse
- #find ⇒ Object
-
#initialize(start_dir: Dir.pwd, path: nil, env_file: nil) ⇒ ConfigLoader
constructor
A new instance of ConfigLoader.
- #load ⇒ Object
Constructor Details
#initialize(start_dir: Dir.pwd, path: nil, env_file: nil) ⇒ ConfigLoader
Returns a new instance of ConfigLoader.
11 12 13 14 15 |
# File 'lib/wip/config_loader.rb', line 11 def initialize(start_dir: Dir.pwd, path: nil, env_file: nil) @start_dir = Pathname(start_dir). @path = path @env_file = env_file end |
Instance Method Details
#find ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/wip/config_loader.rb', line 17 def find return Pathname(@path). if @path @start_dir.ascend do |directory| candidate = directory.join(FILENAME) return candidate if candidate.file? end nil end |
#load ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/wip/config_loader.rb', line 27 def load path = find raise ConfigError, "wip.yml was not found (searched from #{@start_dir} to the filesystem root)" unless path&.file? data = YAML.safe_load_file(path, permitted_classes: [], aliases: false) || {} Config.new(data, path, @env_file) rescue Psych::Exception => e raise ConfigError, "Could not parse #{path}: #{e.}" end |