Class: Hashie::Extensions::Parsers::YamlErbParser

Inherits:
Object
  • Object
show all
Defined in:
lib/hashie/extensions/parsers/yaml_erb_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, options = {}) ⇒ YamlErbParser

Returns a new instance of YamlErbParser.


9
10
11
12
13
# File 'lib/hashie/extensions/parsers/yaml_erb_parser.rb', line 9

def initialize(file_path, options = {})
  @content = File.read(file_path)
  @file_path = file_path.is_a?(Pathname) ? file_path.to_s : file_path
  @options = options
end

Class Method Details

.perform(file_path, options = {}) ⇒ Object


25
26
27
# File 'lib/hashie/extensions/parsers/yaml_erb_parser.rb', line 25

def self.perform(file_path, options = {})
  new(file_path, options).perform
end

Instance Method Details

#performObject


15
16
17
18
19
20
21
22
23
# File 'lib/hashie/extensions/parsers/yaml_erb_parser.rb', line 15

def perform
  template = ERB.new(@content)
  template.filename = @file_path
  permitted_classes = @options.fetch(:permitted_classes) { [] }
  permitted_symbols = @options.fetch(:permitted_symbols) { [] }
  aliases = @options.fetch(:aliases) { true }

  yaml_safe_load(template, permitted_classes, permitted_symbols, aliases)
end