Class: Awestruct::CLI::Manifest::TemplateFile

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/cli/manifest.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, input_path, state = {}) ⇒ TemplateFile

Returns a new instance of TemplateFile.



226
227
228
229
230
# File 'lib/awestruct/cli/manifest.rb', line 226

def initialize(path, input_path, state = {})
  @path = path
  @input_path = input_path
  @state = state
end

Instance Method Details

#perform(dir) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/awestruct/cli/manifest.rb', line 232

def perform(dir)

  begin
  rendered = ERB.new(File.read(@input_path), trim_mode: '<>').result(
    OpenStruct.new(@state).instance_eval { binding })
  rescue => e
    $LOG.debug "::DEBUG:: #{e.message} state - #{@state}"
  end

  p = File.join(dir, @path)
  $LOG.info "Create file: #{p}" if $LOG.info?
  File.open(p, 'w') { |f| f.write(rendered) }
end

#unperform(dir) ⇒ Object



246
247
248
# File 'lib/awestruct/cli/manifest.rb', line 246

def unperform(dir)
  # nothing
end