Sha256: c4e592e798a6560adec4126fcbaf79aafa313969f9df39b15ed633f1a8e1eb78

Contents?: true

Size: 1.71 KB

Versions: 97

Compression:

Stored size: 1.71 KB

Contents

module Convection
  module Model
    class Template
      # Base class for {http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-product-property-reference.html Resource Property Types}
      class ResourceProperty
        class << self
          def properties
            @properties ||= {}
          end

          def property(accesor, property_name, options = {})
            properties[accesor] = Resource::Property.create(accesor, property_name, options)
            properties[accesor].attach(self)
          end

          def attach_method(name, &block)
            define_method(name, &block)
          end
        end

        include DSL::Helpers

        ##
        # Resource Property Instance Methods
        ##
        attr_reader :template
        attr_reader :properties
        attr_reader :exist
        alias_method :exist?, :exist

        def initialize(parent)
          @template = parent.template
          @exist = false

          ## Instantiate properties
          @properties = Model::Collection.new
          resource = self
          resource.class.properties.each do |_, property|
            @properties[property.property_name] = property.instance(resource)
          end
        end

        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

        def render
          properties.map(true, &:render)
        end
      end
    end
  end
end

## Require all resource properties
Dir.glob(File.expand_path('../resource_property/*.rb', __FILE__)) do |r|
  require_relative r
end

Version data entries

97 entries across 97 versions & 1 rubygems

Version Path
convection-0.4.1 lib/convection/model/template/resource_property.rb
convection-0.4.0 lib/convection/model/template/resource_property.rb
convection-0.3.3.pre.beta.1 lib/convection/model/template/resource_property.rb
convection-0.3.2 lib/convection/model/template/resource_property.rb
convection-0.3.1 lib/convection/model/template/resource_property.rb
convection-0.3.0 lib/convection/model/template/resource_property.rb
convection-0.2.34.pre.beta.1 lib/convection/model/template/resource_property.rb
convection-0.2.33 lib/convection/model/template/resource_property.rb
convection-0.2.32 lib/convection/model/template/resource_property.rb
convection-0.2.31 lib/convection/model/template/resource_property.rb
convection-0.2.30 lib/convection/model/template/resource_property.rb
convection-0.2.29 lib/convection/model/template/resource_property.rb
convection-0.2.28 lib/convection/model/template/resource_property.rb
convection-0.2.27 lib/convection/model/template/resource_property.rb
convection-0.2.26 lib/convection/model/template/resource_property.rb
convection-0.2.25 lib/convection/model/template/resource_property.rb
convection-0.2.24 lib/convection/model/template/resource_property.rb
convection-0.2.23 lib/convection/model/template/resource_property.rb
convection-0.2.22 lib/convection/model/template/resource_property.rb
convection-0.2.21 lib/convection/model/template/resource_property.rb