blob: 05edc4084755d4813ec72926262d565705e021f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
require 'yaml'
require 'erb'
require 'pathname'
module Hashie
module Extensions
module Parsers
class YamlErbParser
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
def perform
template = ERB.new(@content)
template.filename = @file_path
whitelist_classes = @options.fetch(:whitelist_classes) { [] }
whitelist_symbols = @options.fetch(:whitelist_symbols) { [] }
aliases = @options.fetch(:aliases) { true }
YAML.safe_load template.result, whitelist_classes, whitelist_symbols, aliases
end
def self.perform(file_path, options = {})
new(file_path, options).perform
end
end
end
end
end
|