Class: ActiveSupport::ConfigurationFile
- Defined in:
- lib/active_support/configuration_file.rb
Overview
Reads a YAML configuration file, evaluating any ERB, then parsing the resulting YAML.
Warns in case of YAML confusing characters, like invisible non-breaking spaces.
Defined Under Namespace
Classes: FormatError
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(content_path) ⇒ ConfigurationFile
constructor
A new instance of ConfigurationFile.
- #parse(context: nil, **options) ⇒ Object
Constructor Details
#initialize(content_path) ⇒ ConfigurationFile
Returns a new instance of ConfigurationFile.
12 13 14 15 |
# File 'lib/active_support/configuration_file.rb', line 12 def initialize(content_path) @content_path = content_path.to_s @content = read content_path end |
Class Method Details
.parse(content_path, **options) ⇒ Object
17 18 19 |
# File 'lib/active_support/configuration_file.rb', line 17 def self.parse(content_path, **) new(content_path).parse(**) end |
Instance Method Details
#parse(context: nil, **options) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/active_support/configuration_file.rb', line 21 def parse(context: nil, **) YAML.load(render(context), **) || {} rescue Psych::SyntaxError => error raise "YAML syntax error occurred while parsing #{@content_path}. " \ "Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \ "Error: #{error.}" end |