2014-07-14 11:31:34 +00:00
|
|
|
require 'yaml'
|
|
|
|
require 'erb'
|
2018-02-06 09:03:24 +00:00
|
|
|
require 'pathname'
|
|
|
|
|
2014-07-14 11:31:34 +00:00
|
|
|
module Hashie
|
|
|
|
module Extensions
|
|
|
|
module Parsers
|
|
|
|
class YamlErbParser
|
2019-03-22 19:04:22 +00:00
|
|
|
def initialize(file_path, options = {})
|
2014-07-14 11:31:34 +00:00
|
|
|
@content = File.read(file_path)
|
2015-12-25 18:41:05 +00:00
|
|
|
@file_path = file_path.is_a?(Pathname) ? file_path.to_s : file_path
|
2019-03-22 19:04:22 +00:00
|
|
|
@options = options
|
2014-07-14 11:31:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
2014-09-16 08:49:23 +00:00
|
|
|
template = ERB.new(@content)
|
|
|
|
template.filename = @file_path
|
2019-03-22 19:04:22 +00:00
|
|
|
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
|
2014-07-14 11:31:34 +00:00
|
|
|
end
|
|
|
|
|
2019-03-22 19:04:22 +00:00
|
|
|
def self.perform(file_path, options = {})
|
|
|
|
new(file_path, options).perform
|
2014-07-14 11:31:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|