Sha256: 4e45a35a9dd54191a50623445c4351f529b36ebf4c516ef936f80a806657fd71

Contents?: true

Size: 1.05 KB

Versions: 31

Compression:

Stored size: 1.05 KB

Contents

module Terraspace::Compiler
  class Writer
    include Basename
    include Terraspace::Util

    def initialize(mod, options={})
      @mod, @options = mod, options
      @src_path = options[:src_path]
      @dest_name = options[:dest_name] # override generated name
    end

    def dest_path
      name = get_name
      name = basename(name)
      "#{dest_dir}/#{name}"
    end

    def get_name
      return @dest_name if @dest_name
      return @src_path if Terraspace.pass_file?(@src_path)
      @src_path.sub('.rb','.tf.json')
    end

    def dest_dir
      if @mod.is_a?(Terraspace::Mod::Remote)
        File.dirname(@src_path) # for Mod::Remote src is dest
      else
        @mod.cache_dir
      end
    end

    def write(content)
      FileUtils.mkdir_p(File.dirname(dest_path))
      if content.respond_to?(:path) # IO filehandle
        FileUtils.cp(content.path, dest_path) # preserves permission
      else # just content
        IO.write(dest_path, content)
      end
      logger.debug "Created #{Terraspace::Util.pretty_path(dest_path)}"
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
terraspace-1.1.3 lib/terraspace/compiler/writer.rb
terraspace-1.1.2 lib/terraspace/compiler/writer.rb
terraspace-1.1.1 lib/terraspace/compiler/writer.rb
terraspace-1.1.0 lib/terraspace/compiler/writer.rb
terraspace-1.0.6 lib/terraspace/compiler/writer.rb
terraspace-1.0.5 lib/terraspace/compiler/writer.rb
terraspace-1.0.4 lib/terraspace/compiler/writer.rb
terraspace-1.0.3 lib/terraspace/compiler/writer.rb
terraspace-1.0.2 lib/terraspace/compiler/writer.rb
terraspace-1.0.1 lib/terraspace/compiler/writer.rb
terraspace-1.0.0 lib/terraspace/compiler/writer.rb
terraspace-0.7.2 lib/terraspace/compiler/writer.rb
terraspace-0.7.1 lib/terraspace/compiler/writer.rb
terraspace-0.7.0 lib/terraspace/compiler/writer.rb
terraspace-0.6.23 lib/terraspace/compiler/writer.rb
terraspace-0.6.22 lib/terraspace/compiler/writer.rb
terraspace-0.6.21 lib/terraspace/compiler/writer.rb
terraspace-0.6.20 lib/terraspace/compiler/writer.rb
terraspace-0.6.19 lib/terraspace/compiler/writer.rb
terraspace-0.6.18 lib/terraspace/compiler/writer.rb