Class: Cloudruler::Template
- Inherits:
-
Object
- Object
- Cloudruler::Template
- Defined in:
- lib/cloudruler/template.rb
Defined Under Namespace
Classes: EvalContext
Constant Summary collapse
- DEFAULT_FORMAT_VERSION =
'2010-09-09'.freeze
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#format_version ⇒ Object
Returns the value of attribute format_version.
-
#rulers ⇒ Object
Returns the value of attribute rulers.
Instance Method Summary collapse
- #body ⇒ Object
- #dump ⇒ Object
-
#initialize(runner, path) ⇒ Template
constructor
A new instance of Template.
- #resolve ⇒ Object
- #resolve_ruler(ruler_name, options, &block) ⇒ Object
Constructor Details
#initialize(runner, path) ⇒ Template
Returns a new instance of Template.
7 8 9 10 11 12 13 |
# File 'lib/cloudruler/template.rb', line 7 def initialize(runner, path) @runner = runner @path = path @rulers = [] @format_version = DEFAULT_FORMAT_VERSION @description = '' end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/cloudruler/template.rb', line 5 def description @description end |
#format_version ⇒ Object
Returns the value of attribute format_version.
5 6 7 |
# File 'lib/cloudruler/template.rb', line 5 def format_version @format_version end |
#rulers ⇒ Object
Returns the value of attribute rulers.
5 6 7 |
# File 'lib/cloudruler/template.rb', line 5 def rulers @rulers end |
Instance Method Details
#body ⇒ Object
40 41 42 |
# File 'lib/cloudruler/template.rb', line 40 def body @body ||= File.read(@path) end |
#dump ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cloudruler/template.rb', line 22 def dump result = { 'AWSTemplateFormatVersion' => @format_version, 'Description' => @description, } result['Metadata'] = @rulers.map(&:metadata).compact.map(&:content) result['Parameters'] = @rulers.map(&:parameters).compact.map(&:content) result['Mappings'] = @rulers.map(&:mappings).compact.map(&:content) result['Conditions'] = @rulers.map(&:conditions).compact.map(&:content) result['Transform'] = @rulers.map(&:transform).compact.map(&:content) result['Resources'] = @rulers.map(&:resources).compact.map(&:content) result['Outputs'] = @rulers.map(&:outputs).compact.map(&:content) result = result.reject { |_, v| v.empty? }.each_with_object({}) do |(k, v), obj| v.respond_to?(:reduce) ? obj[k] = v.reduce(&:merge) : obj[k] = v end result.to_yaml end |
#resolve ⇒ Object
15 16 17 18 19 20 |
# File 'lib/cloudruler/template.rb', line 15 def resolve @rulers = [] context = EvalContext.new(self) context.instance_eval(body) self end |
#resolve_ruler(ruler_name, options, &block) ⇒ Object
44 45 46 47 |
# File 'lib/cloudruler/template.rb', line 44 def resolve_ruler(ruler_name, , &block) ruler = @runner.find_ruler(ruler_name) ruler.resolve(, &block) end |