class RgGen::Core::OutputBase::FileWriter
Public Class Methods
new(pattern, &body)
click to toggle source
# File lib/rggen/core/output_base/file_writer.rb, line 7 def initialize(pattern, &body) @pattern = Erubi::Engine.new(pattern) @body = body end
Public Instance Methods
write_file(context, directory = nil)
click to toggle source
# 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
Private Instance Methods
create_directory(path)
click to toggle source
# File lib/rggen/core/output_base/file_writer.rb, line 33 def create_directory(path) directory = path.dirname directory.directory? || directory.mkpath end
generate_content(context, path)
click to toggle source
# File lib/rggen/core/output_base/file_writer.rb, line 27 def generate_content(context, path) content = context.create_blank_file(path) @body && context.instance_exec(content, &@body) content end
generate_path(context, directory)
click to toggle source
# File lib/rggen/core/output_base/file_writer.rb, line 21 def generate_path(context, directory) [ *Array(directory), context.instance_eval(@pattern.src) ].map(&:to_s).reject(&:empty?).to_path end