Created
November 23, 2013 11:57
-
-
Save vadv/7613799 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ostruct' | |
module ErbCompile | |
def erb_compile(atr) | |
case | |
when atr.kind_of?(Hash), atr.kind_of?(Array) # Chef::Node::ImmutableArray | |
JSON.parse erb_compile(JSON.generate(JSON.parse(atr.to_json))) | |
when atr.kind_of?(String) | |
values = OpenStruct.new({:node => self.node}) | |
ERB.new(atr).result(values.instance_eval{ binding }) | |
when atr.kind_of?(Integer), atr.kind_of?(Float), atr.kind_of?(TrueClass), atr.kind_of?(FalseClass), atr.kind_of?(NilClass) | |
atr | |
else | |
raise "[ErbCompile::erb_compile] #{atr.class} not supported yet" | |
end | |
end | |
end | |
[ Chef::Recipe, Chef::Mixin::Template::TemplateContext ].each do |klass| | |
klass.send(:include, ErbCompile) unless klass.respond_to?('erb_compile') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment