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



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

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

Instance Method Details

#perform(dir) ⇒ Object



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

def perform(dir)

  begin
  rendered = ERB.new(File.read(@input_path), nil, '<>').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



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

def unperform(dir)
  # nothing
end