Class: Pears::Provider::RailsConfig

Inherits:
Base
  • Object
show all
Defined in:
lib/pears/provider/rails_config.rb

Overview

Used for loading simple YAML file locally.

Instance Attribute Summary

Attributes inherited from Base

#data

Instance Method Summary collapse

Methods inherited from Base

#[], #each, #has_key?, #purge

Constructor Details

#initialize(*path_parts, on_failure: :raise) ⇒ RailsConfig

Returns a new instance of RailsConfig.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pears/provider/rails_config.rb', line 8

def initialize(*path_parts, on_failure: :raise)
  file = path_parts.pop
  file_path = Rails.root.join('config', *path_parts, "#{file}.yml")
  yaml_data = File.read(file_path)
  @data = parse_yaml(yaml_data)
rescue Errno::ENOENT,
    Pears::InvalidProviderData => error
  if on_failure == :null
    @data = {}
  else
    raise error
  end
end