Class: Aws::Cfn::Dsl::Template
- Defined in:
- lib/aws/cfn/dsl/template.rb
Instance Attribute Summary collapse
-
#dict ⇒ Object
readonly
Returns the value of attribute dict.
Instance Method Summary collapse
- #file(b) ⇒ Object
- #hash_refs(line, scope) ⇒ Object
-
#initialize(path = nil, &block) ⇒ Template
constructor
A new instance of Template.
- #mapping(name, options = nil) ⇒ Object
-
#output(name, options = nil) ⇒ Object
def resource_file(p) file “Resources/#p.rb” end.
-
#parameter(name, options = nil) ⇒ Object
def mapping_file(p) file “Mappings/#p.rb” end.
-
#resource(name, options = nil) ⇒ Object
def parameter_file(p) file “Parameters/#p.rb” end.
Constructor Details
#initialize(path = nil, &block) ⇒ Template
Returns a new instance of Template.
15 16 17 18 19 20 |
# File 'lib/aws/cfn/dsl/template.rb', line 15 def initialize(path=nil,&block) @path = path || File.dirname(caller[2].split(%r'\s+').shift.split(':')[0]) super() do # We do nothing with the template for now end end |
Instance Attribute Details
#dict ⇒ Object (readonly)
Returns the value of attribute dict.
9 10 11 |
# File 'lib/aws/cfn/dsl/template.rb', line 9 def dict @dict end |
Instance Method Details
#file(b) ⇒ Object
22 23 24 25 |
# File 'lib/aws/cfn/dsl/template.rb', line 22 def file(b) block = File.read File.join(@path,b) eval block end |
#hash_refs(line, scope) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/aws/cfn/dsl/template.rb', line 71 def hash_refs(line,scope) block_regex = %r/\{\s*:\S+\s*=>.*?\}|\{\s*\S+:\s*.*?\}/ match = line.match %r/^([^#]*?)(#{block_regex})(.*)$/ if match left = match[1] code = match[2] tail = match[3] while true braces = code.gsub(%r/[^{}]+/, '') len = braces.size if len % 2 != 0 nest = tail.match %r/^(.*?\})(.*)$/ if nest code += nest[1] tail = nest[2] else abort! "Mismatched {}'s" end else break end end h = nil eval "h = #{code}", binding k = h.keys[0] v = h.delete(k) v = scope[:compiler].sym_to_s(v) h[k.to_s] = v scope[:logger].debug h [left, h, tail.size > 0 ? hash_refs(tail,scope) : tail ] else "#{line}\n" end end |
#mapping(name, options = nil) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/aws/cfn/dsl/template.rb', line 27 def mapping(name, =nil) if .nil? file "Mappings/#{name}.rb" else super(name,) end end |
#output(name, options = nil) ⇒ Object
def resource_file(p)
file "Resources/#{p}.rb"
end
63 64 65 66 67 68 69 |
# File 'lib/aws/cfn/dsl/template.rb', line 63 def output(name, =nil) if .nil? file "Outputs/#{name}.rb" else super(name,) end end |
#parameter(name, options = nil) ⇒ Object
def mapping_file(p)
file "Mappings/#{p}.rb"
end
39 40 41 42 43 44 45 |
# File 'lib/aws/cfn/dsl/template.rb', line 39 def parameter(name, =nil) if .nil? file "Parameters/#{name}.rb" else super(name,) end end |
#resource(name, options = nil) ⇒ Object
def parameter_file(p)
file "Parameters/#{p}.rb"
end
51 52 53 54 55 56 57 |
# File 'lib/aws/cfn/dsl/template.rb', line 51 def resource(name, =nil) if .nil? file "Resources/#{name}.rb" else super(name,) end end |