Sha256: c3bf53df1f6d70734232f74ed51c3538c343833cb7443e6b82facf55bd6f3710

Contents?: true

Size: 1.17 KB

Versions: 15

Compression:

Stored size: 1.17 KB

Contents

require "rake"
require "rake/tasklib"
require "cfndsl"

module CfnDsl
  class RakeTask < Rake::TaskLib
    attr_accessor :cfndsl_opts

    def initialize(name = nil)
      yield self if block_given?

      desc "Generate Cloudformation" unless ::Rake.application.last_comment
      task(name || :generate) do |_t, _args|
        cfndsl_opts[:files].each do |opts|
          generate(opts)
        end
      end
    end

    private

    def generate(opts)
      log(opts)
      outputter(opts).puts model(opts[:filename])
    end

    def log(opts)
      type = opts[:output].nil? ? "STDOUT" : opts[:output]
      verbose.puts("Writing to #{type}") if verbose
    end

    def outputter(opts)
      opts[:output].nil? ? STDOUT : file_output(opts[:output])
    end

    def model(filename)
      fail "#{filename} doesn't exist" unless File.exist? filename
      verbose.puts("using extras #{extra}") if verbose
      CfnDsl.eval_file_with_extras(filename, extra, verbose).to_json
    end

    def extra
      cfndsl_opts.fetch(:extras, [])
    end

    def verbose
      cfndsl_opts[:verbose] && STDERR
    end

    def file_output(path)
      File.open(File.expand_path(path), "w")
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
cfndsl-0.3.6 lib/cfndsl/rake_task.rb
cfndsl-0.3.5 lib/cfndsl/rake_task.rb
cfndsl-0.3.4 lib/cfndsl/rake_task.rb
cfndsl-0.3.3 lib/cfndsl/rake_task.rb
cfndsl-0.3.2 lib/cfndsl/rake_task.rb
cfndsl-0.3.1 lib/cfndsl/rake_task.rb
cfndsl-0.2.9 lib/cfndsl/rake_task.rb
cfndsl-0.2.8 lib/cfndsl/rake_task.rb
cfndsl-0.3.0 lib/cfndsl/rake_task.rb
cfndsl-0.2.7 lib/cfndsl/rake_task.rb
cfndsl-0.2.4 lib/cfndsl/rake_task.rb
cfndsl-0.2.3 lib/cfndsl/rake_task.rb
cfndsl-0.2.2 lib/cfndsl/rake_task.rb
cfndsl-0.2.1 lib/cfndsl/rake_task.rb
cfndsl-0.2.0 lib/cfndsl/rake_task.rb