Sha256: a16a98ddcbc7fe3965ec613ba11662fc893054a75cedd98b66a6f5a08b87a0bd

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require_relative '../control/stack'
require_relative '../dsl/helpers'
require_relative '../model/attributes'
require_relative '../model/template'

module Convection
  module DSL
    ##
    # DSL for Cloudfile
    ##
    module Cloudfile
      include DSL::Helpers

      attribute :name
      attribute :region
      attribute :splay

      ## Helper to define a template in-line
      def template(*args, &block)
        Model::Template.new(*args, &block)
      end

      def attribute(stack, key, value)
        @attributes.set(stack, key, value)
      end

      # Adds a stack with the provided options to the list of stacks.
      #
      # @see Convection::Control::Stack#initialize
      def stack(stack_name, template, options = {}, &block)
        options[:region] ||= region
        options[:cloud] = name
        options[:attributes] = attributes

        @stacks[stack_name] = Control::Stack.new(stack_name, template, options, &block)
        @deck << @stacks[stack_name]
      end
    end
  end

  module Model
    ##
    # Define your Clouds
    ##
    class Cloudfile
      include DSL::Cloudfile

      attr_reader :attributes
      attr_reader :stacks
      attr_reader :deck

      def initialize(cloudfile)
        @attributes = Model::Attributes.new
        @stacks = {}
        @deck = []

        instance_eval(IO.read(cloudfile), cloudfile, 1)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
convection-0.2.34.pre.beta.1 lib/convection/model/cloudfile.rb