Class: ActiveSupport::ConfigurationFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/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 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/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
28
29
30
31
32
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/configuration_file.rb', line 21

def parse(context: nil, **options)
  source = render(context)
  if YAML.respond_to?(:unsafe_load)
    YAML.unsafe_load(source, **options) || {}
  else
    YAML.load(source, **options) || {}
  end
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