Sha256: c83103c4386f7c509fbcf6b008ea9d4ec8236798eea92a9040d8bc606f98997d

Contents?: true

Size: 952 Bytes

Versions: 36

Compression:

Stored size: 952 Bytes

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 = @dest_name || @src_path.sub('.rb','.tf.json')
      name = basename(name)
      "#{dest_dir}/#{name}"
    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

36 entries across 36 versions & 1 rubygems

Version Path
terraspace-0.6.5 lib/terraspace/compiler/writer.rb
terraspace-0.6.4 lib/terraspace/compiler/writer.rb
terraspace-0.6.3 lib/terraspace/compiler/writer.rb
terraspace-0.6.2 lib/terraspace/compiler/writer.rb
terraspace-0.6.1 lib/terraspace/compiler/writer.rb
terraspace-0.6.0 lib/terraspace/compiler/writer.rb
terraspace-0.5.12 lib/terraspace/compiler/writer.rb
terraspace-0.5.11 lib/terraspace/compiler/writer.rb
terraspace-0.5.10 lib/terraspace/compiler/writer.rb
terraspace-0.5.9 lib/terraspace/compiler/writer.rb
terraspace-0.5.8 lib/terraspace/compiler/writer.rb
terraspace-0.5.7 lib/terraspace/compiler/writer.rb
terraspace-0.5.6 lib/terraspace/compiler/writer.rb
terraspace-0.5.5 lib/terraspace/compiler/writer.rb
terraspace-0.5.4 lib/terraspace/compiler/writer.rb
terraspace-0.5.3 lib/terraspace/compiler/writer.rb
terraspace-0.5.2 lib/terraspace/compiler/writer.rb
terraspace-0.5.1 lib/terraspace/compiler/writer.rb
terraspace-0.5.0 lib/terraspace/compiler/writer.rb
terraspace-0.4.4 lib/terraspace/compiler/writer.rb