Class: RgGen::Core::OutputBase::FileWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/rggen/core/output_base/file_writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(pattern, &body) ⇒ FileWriter

Returns a new instance of FileWriter.



7
8
9
10
# File 'lib/rggen/core/output_base/file_writer.rb', line 7

def initialize(pattern, &body)
  @pattern = Erubi::Engine.new(pattern)
  @body = body
end

Instance Method Details

#write_file(context, directory = nil) ⇒ Object



12
13
14
15
16
17
# File 'lib/rggen/core/output_base/file_writer.rb', line 12

def write_file(context, directory = nil)
  path = generate_path(context, directory)
  content = generate_content(context, path)
  create_directory(path)
  File.binwrite(path, content)
end