class Convection::Model::Template::Resource
Attributes
exist[R]
exist?[R]
name[R]
parent[R]
properties[R]
resource_attributes[R]
template[R]
Public Class Methods
attach_method(name, &block)
click to toggle source
# File lib/convection/model/template/resource.rb, line 40 def attach_method(name, &block) define_method(name, &block) end
new(name, parent)
click to toggle source
# File lib/convection/model/template/resource.rb, line 295 def initialize(name, parent) @name = name @parent = parent @template = parent.template @type = self.class.type @depends_on = [] @deletion_policy = nil @exist = false @resource_attributes = [] ## Instantiate properties @properties = Model::Collection.new resource = self resource.class.properties.each do |_, property| @properties[property.property_name] = property.instance(resource) end end
properties()
click to toggle source
# File lib/convection/model/template/resource.rb, line 17 def properties @properties ||= {} end
property(accesor, property_name, options = {})
click to toggle source
# File lib/convection/model/template/resource.rb, line 30 def property(accesor, property_name, options = {}) ## Handle usage of old property interface options = {}.tap do |o| o[:type] = options end if options.is_a?(Symbol) properties[accesor] = Property.create(accesor, property_name, options) properties[accesor].attach(self) end
type(cf_type = nil, dsl_name = nil)
click to toggle source
# File lib/convection/model/template/resource.rb, line 21 def type(cf_type = nil, dsl_name = nil) return @type if cf_type.nil? @type = cf_type @name = dsl_name || DSL::Helpers.method_name(cf_type) DSL::Template::Resource.attach_resource(@name, self) end
Public Instance Methods
as_attribute(attr_name, attr_type = :string)
click to toggle source
# File lib/convection/model/template/resource.rb, line 349 def as_attribute(attr_name, attr_type = :string) @template.attribute_mappings[name] = { :name => attr_name, :type => attr_type } end
deletion_policy(deletion_policy = :unset_deletion_policy)
click to toggle source
We don't want to use an accessor (e.g. deletion_policy
=) because this is a DSL
method
# File lib/convection/model/template/resource.rb, line 328 def deletion_policy(deletion_policy = :unset_deletion_policy) return @deletion_policy if deletion_policy == :unset_deletion_policy @deletion_policy = deletion_policy end
depends_on(resource)
click to toggle source
# File lib/convection/model/template/resource.rb, line 322 def depends_on(resource) @depends_on << (resource.is_a?(Resource) ? resource.name : resource) end
property(key, *value)
click to toggle source
# File lib/convection/model/template/resource.rb, line 314 def property(key, *value) return properties[key].value if value.empty? ## Define a property instance on the fly properties[key] = ScalarPropertyInstance.new(self) unless properties.include?(key) properties[key].set(*value) end
reference()
click to toggle source
# File lib/convection/model/template/resource.rb, line 334 def reference { 'Ref' => name } end
render()
click to toggle source
# File lib/convection/model/template/resource.rb, line 356 def render { 'Type' => type, 'Properties' => properties.map(true, &:render) }.tap do |resource| resource_attributes.map { |a| a.render resource } resource['DependsOn'] = @depends_on unless @depends_on.empty? resource['DeletionPolicy'] = @deletion_policy unless @deletion_policy.nil? render_condition(resource) end end
type()
click to toggle source
Resource
Instance Methods
# File lib/convection/model/template/resource.rb, line 286 attribute :type
with_output(output_name = name, value = reference, &block)
click to toggle source
# File lib/convection/model/template/resource.rb, line 340 def with_output(output_name = name, value = reference, &block) o = Model::Template::Output.new(output_name, @template) o.value = value o.description = "Resource #{ type }/#{ name }" o.instance_exec(&block) if block @template.outputs[output_name] = o end