Class: Aws::Cfn::Dsl::Template

Inherits:
TemplateDSL
  • Object
show all
Defined in:
lib/aws/cfn/dsl/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil, &block) ⇒ Template

Returns a new instance of Template.



17
18
19
20
21
22
# File 'lib/aws/cfn/dsl/template.rb', line 17

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

#dictObject (readonly)

Returns the value of attribute dict.



11
12
13
# File 'lib/aws/cfn/dsl/template.rb', line 11

def dict
  @dict
end

Instance Method Details

#file(b) ⇒ Object



24
25
26
27
# File 'lib/aws/cfn/dsl/template.rb', line 24

def file(b)
  block = File.read File.join(@path,b)
  eval block
end

#hash_refs(line, scope) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/aws/cfn/dsl/template.rb', line 73

def hash_refs(line,scope)
  match = line.match %r/^(.*?)(\{\s*:\S+\s*=>.*?\}|\{\s*\S+:\s*.*?\})(.*)$/
  if match
    h = nil
    eval "h = #{match[2]}", binding
    k = h.keys[0]
    v = h.delete(k)
    v = if v.is_a?Array
          v.map{|e| e.to_s }
        else
          v.to_s
        end

    h[k.to_s] = v
    scope[:logger].debug h
    [match[1], h, hash_refs(match[3],scope) ]
  else
    "#{line}\n"
  end
end

#mapping(name, options = nil) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/aws/cfn/dsl/template.rb', line 29

def mapping(name, options=nil)
  if options.nil?
    file "Mappings/#{name}.rb"
  else
    super(name,options)
  end
end

#output(name, options = nil) ⇒ Object

def resource_file(p)

file "Resources/#{p}.rb"

end



65
66
67
68
69
70
71
# File 'lib/aws/cfn/dsl/template.rb', line 65

def output(name, options=nil)
  if options.nil?
    file "Outputs/#{name}.rb"
  else
    super(name,options)
  end
end

#parameter(name, options = nil) ⇒ Object

def mapping_file(p)

file "Mappings/#{p}.rb"

end



41
42
43
44
45
46
47
# File 'lib/aws/cfn/dsl/template.rb', line 41

def parameter(name, options=nil)
  if options.nil?
    file "Parameters/#{name}.rb"
  else
    super(name,options)
  end
end

#resource(name, options = nil) ⇒ Object

def parameter_file(p)

file "Parameters/#{p}.rb"

end



53
54
55
56
57
58
59
# File 'lib/aws/cfn/dsl/template.rb', line 53

def resource(name, options=nil)
  if options.nil?
    file "Resources/#{name}.rb"
  else
    super(name,options)
  end
end