# YAMLファイルを結合(include)したり、Hash化(load)したりする
#
# 使い方)
# aaa.yml -------
# - id: <%= id %>
# aaa: 'aaaa'
#
# bbb.yml -------
# - id: <%= id %>
# bbb: 'bbbb'
#
# result.yml ------
# <%= Util::Yaml.include('aaa.yml', { id: 1 }) %>
# <%= Util::Yaml.include('bbb.yml', { id: 2 }) %>
#
module Util
class Yaml
def self.include(file_path, locals = {})
Erubis::Eruby.new(IO.read(file_path)).result(locals)
end
def self.load(file_path, locals = {})
YAML::load(include(file_path, locals))
end
end
end
More than 5 years have passed since last update.
YAML内でYAMLをincludeする(render :partialみたいな感じ)
Last updated at Posted at 2015-12-11
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme