Class: ActiveSupport::ConfigurationFile
Do not use. This class is for internal use only.
Relationships & Source Files | |
Namespace Children | |
Exceptions:
| |
Inherits: | Object |
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.
Class Method Summary
Instance Method Summary
- #parse(context: nil, **options)
- #read(content_path) private
- #render(context) private
Constructor Details
.new(content_path) ⇒ ConfigurationFile
# 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)
[ GitHub ]# File 'activesupport/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)
[ GitHub ]# File 'activesupport/lib/active_support/configuration_file.rb', line 21
def parse(context: nil, ** ) source = @content.include?("<%") ? render(context) : @content if source == @content if YAML.respond_to?(:unsafe_load) YAML.unsafe_load_file(@content_path, ** ) || {} else YAML.load_file(@content_path, ** ) || {} end else if YAML.respond_to?(:unsafe_load) YAML.unsafe_load(source, ** ) || {} else YAML.load(source, ** ) || {} end 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.}" end
#read(content_path) (private)
[ GitHub ]# File 'activesupport/lib/active_support/configuration_file.rb', line 44
def read(content_path) require "yaml" unless defined?(YAML) File.read(content_path).tap do |content| if content.include?("\u00A0") warn "#{content_path} contains invisible non-breaking spaces, you may want to remove those" end end end