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.



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

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

Instance Method Details

#perform(dir) ⇒ Object



231
232
233
234
235
236
237
238
239
# File 'lib/awestruct/cli/manifest.rb', line 231

def perform(dir)

  rendered = ERB.new(File.read(@input_path), nil, '<>').result(
    OpenStruct.new(@state).instance_eval { binding })

  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



241
242
243
# File 'lib/awestruct/cli/manifest.rb', line 241

def unperform(dir)
  # nothing
end