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.
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.} 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 |