lib/convection/model/template.rb in convection-0.3.2 vs lib/convection/model/template.rb in convection-0.3.3.pre.beta.1
- old
+ new
@@ -22,10 +22,16 @@
resource.instance_exec(&block) if block
resources[rname] = resource
end
end
+
+ def attach_resource_collection(name, klass)
+ define_method(name) do |rname, &block|
+ resource_collections[rname] = klass.new(rname, self, &block)
+ end
+ end
end
end
include DSL::Helpers
include DSL::Template::Resource
@@ -185,10 +191,11 @@
attr_reader :attribute_mappings
attr_reader :parameters
attr_reader :mappings
attr_reader :conditions
+ attr_reader :resource_collections
attr_reader :resources
attr_reader :outputs
def template
self
@@ -205,20 +212,26 @@
@parameters = Collection.new
@mappings = Collection.new
@conditions = Collection.new
@resources = Collection.new
+ @resource_collections = Collection.new
@outputs = Collection.new
@metadata = Collection.new
end
def clone(stack_)
Template.new(stack_, &@definition)
end
def execute
instance_exec(&@definition)
+
+ resource_collections.each do |_, group|
+ group.run_definition
+ group.execute
+ end
end
def render(stack_ = nil)
## Instantiate a new template with the definition block and an other stack
return clone(stack_).render unless stack_.nil?
@@ -229,16 +242,22 @@
'AWSTemplateFormatVersion' => version,
'Description' => description,
'Parameters' => parameters.map(&:render),
'Mappings' => mappings.map(&:render),
'Conditions' => conditions.map(&:render),
- 'Resources' => resources.map(&:render),
+ 'Resources' => all_resources.map(&:render),
'Outputs' => outputs.map(&:render),
'Metadata' => metadata.map(&:render)
}
end
+ def all_resources
+ resource_collections.reduce(resources) do |result, (_name, resource_collection)|
+ result.merge(resource_collection.resources)
+ end
+ end
+
def diff(other, stack_ = nil)
render(stack_).diff(other).map { |diff| Diff.new(diff[0], *diff[1]) }
end
def to_json(stack_ = nil, pretty = false)
@@ -351,7 +370,8 @@
require_relative 'template/mapping'
require_relative 'template/condition'
require_relative 'template/resource'
require_relative 'template/resource_property'
require_relative 'template/resource_attribute'
+require_relative 'template/resource_collection'
require_relative 'template/output'
require_relative 'template/metadata'