Sha256: 7fd32c36c2fed6c5bab754778ecaa4cd20b9bbe707b54d7bc945f953ae84588c

Contents?: true

Size: 878 Bytes

Versions: 2

Compression:

Stored size: 878 Bytes

Contents

require 'json'

module Stackster
  class StackCreater

    def initialize(args)
      @config = args[:config]
      @entry = args[:entry]
      @name = args[:name]
      @template = read_template_from_file args[:template_file]
      @cf = AWS::CloudFormation.new :config => @config
    end

    def read_template_from_file(template_file)
      file = File.open template_file
      file.read
    end

    def read_parameters_from_template
      t = JSON.parse @template
      t['Parameters'] ? t['Parameters'].keys : []
    end

    def read_parameters_from_entry
      h = {}
      read_parameters_from_template.each do |p|
        h[p] = @entry.attributes[p] if @entry.attributes[p]
      end
      h
    end

    def create
      @cf.create :name => @name,
                 :parameters => read_parameters_from_entry,
                 :template => @template
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stackster-0.1.3 lib/stackster/stack/stack_creater.rb
stackster-0.1.2 lib/stackster/stack/stack_creater.rb