Class: Terraspace::Compiler::Writer
- Inherits:
-
Object
- Object
- Terraspace::Compiler::Writer
- Defined in:
- lib/terraspace/compiler/writer.rb
Instance Method Summary collapse
- #dest_dir ⇒ Object
- #dest_path ⇒ Object
-
#initialize(mod, options = {}) ⇒ Writer
constructor
A new instance of Writer.
- #write(content) ⇒ Object
Methods included from Util
Methods included from Util::Sure
Methods included from Util::Sh
Methods included from Util::Logging
Methods included from Basename
Constructor Details
#initialize(mod, options = {}) ⇒ Writer
Returns a new instance of Writer.
6 7 8 9 10 |
# File 'lib/terraspace/compiler/writer.rb', line 6 def initialize(mod, ={}) @mod, @options = mod, @src_path = [:src_path] @dest_name = [:dest_name] # override generated name end |
Instance Method Details
#dest_dir ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/terraspace/compiler/writer.rb', line 18 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 |
#dest_path ⇒ Object
12 13 14 15 16 |
# File 'lib/terraspace/compiler/writer.rb', line 12 def dest_path name = @dest_name || @src_path.sub('.rb','.tf.json') name = basename(name) "#{dest_dir}/#{name}" end |
#write(content) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/terraspace/compiler/writer.rb', line 26 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 |