Class: Awestruct::CLI::Manifest::TemplateFile
- Inherits:
-
Object
- Object
- Awestruct::CLI::Manifest::TemplateFile
- Defined in:
- lib/awestruct/cli/manifest.rb
Instance Method Summary collapse
-
#initialize(path, input_path, state = {}) ⇒ TemplateFile
constructor
A new instance of TemplateFile.
- #perform(dir) ⇒ Object
- #unperform(dir) ⇒ Object
Constructor Details
#initialize(path, input_path, state = {}) ⇒ TemplateFile
Returns a new instance of 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.} 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 |