Class: ActiveSupport::ConfigurationFile

Inherits:
Object
  • Object
show all
Defined in:
activesupport/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

Constructor Details

#initialize(content_path) ⇒ ConfigurationFile

Returns a new instance of ConfigurationFile.


12
13
14
15
# File 'activesupport/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 'activesupport/lib/active_support/configuration_file.rb', line 17

def self.parse(content_path, **options)
  new(content_path).parse(**options)
end

Instance Method Details

#parse(context: nil, **options) ⇒ Object


21
22
23
24
25
26
27
# File 'activesupport/lib/active_support/configuration_file.rb', line 21

def parse(context: nil, **options)
  YAML.load(render(context), **options) || {}
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.message}"
end