lib/pears/provider/local_file.rb in pears-0.0.7 vs lib/pears/provider/local_file.rb in pears-0.0.8
- old
+ new
@@ -3,18 +3,18 @@
module Pears
module Provider
# Used for loading simple YAML file locally.
class LocalFile < Base
- def initialize(file_path)
+ def initialize(file_path, on_failure: :raise)
yaml_data = File.read(file_path)
@data = parse_yaml(yaml_data)
- end
-
- private
-
- def parse_yaml(yaml_data)
- YAML.load(yaml_data).with_indifferent_access
+ rescue Errno::ENOENT => error
+ if on_failure == :null
+ @data = {}
+ else
+ raise error
+ end
end
end
end
end