lib/kumogata/ext/string_ext.rb in kumogata-0.2.0 vs lib/kumogata/ext/string_ext.rb in kumogata-0.2.1
- old
+ new
@@ -44,12 +44,48 @@
data = data.undent if options[:undent]
trim_mode = options[:trim_mode]
null = "\0"
data = Object.new.instance_eval(<<-EOS)
- @__refs__ = []
- def Ref(value); @__refs__ << {'Ref' => value}; #{null.inspect}; end
- ERB.new(#{data.inspect}, nil, #{trim_mode.inspect}).result(binding).split(#{null.inspect}).zip(@__refs__)
+ @__functions__ = []
+
+ @__value_conv__ = proc do |v|
+ case v
+ when Array, Hash
+ v
+ else
+ v.to_s
+ end
+ end
+
+ def Fn__Base64(value)
+ @__functions__ << {'Fn::Base64' => @__value_conv__[value]}
+ #{null.inspect}
+ end
+
+ def Fn__FindInMap(map_name, top_level_key, second_level_key)
+ @__functions__ << {'Fn::FindInMap' => [
+ map_name, top_level_key, second_level_key].map(&@__value_conv__)}
+ #{null.inspect}
+ end
+
+ def Fn__GetAtt(logical_name, attr_name)
+ @__functions__ << {'Fn::GetAtt' => [
+ logical_name, attr_name].map(&@__value_conv__)}
+ #{null.inspect}
+ end
+
+ def Fn__GetAZs(region)
+ @__functions__ << {'Fn::GetAZs' => @__value_conv__[region]}
+ #{null.inspect}
+ end
+
+ def Ref(value)
+ @__functions__ << {'Ref' => value}
+ #{null.inspect}
+ end
+
+ ERB.new(#{data.inspect}, nil, #{trim_mode.inspect}).result(binding).split(#{null.inspect}).zip(@__functions__)
EOS
data = data.flatten.select {|i| not i.nil? }.map {|i|
if i.kind_of?(String)
StringIO.new(i).to_a