Sha256: 31be2aaadcd1bbc8a16f154237bc79ea45881b2772a06f18246ec546460593d6

Contents?: true

Size: 849 Bytes

Versions: 1

Compression:

Stored size: 849 Bytes

Contents

require "cfndsl"

# frozen_string_literal: true
module AwsAsCode
  module Task
    # Compiles all input templates and puts
    # JSON to the output directory
    class Compile
      attr_reader :config

      def initialize(config)
        @config = config
      end

      def execute
        input_files.each { |filename| compile_single_file filename }
      end

      private

      def compile_single_file(filename)
        output_filename = File.basename(filename, ".rb") + ".json"
        output_pathname = File.join config.json_dir, output_filename

        cfn = CfnDsl.eval_file_with_extras(
          filename,
          [],
          STDERR
        )

        File.open(output_pathname, "w") { |f| f.write cfn.to_json }
      end

      def input_files
        Dir.glob(File.join(config.ruby_dir, "**/*.rb"))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aws_as_code-1.0.1 lib/aws_as_code/task/compile.rb