class Expansions::FileMerge

Attributes

read_original_contents[RW]

Public Class Methods

new(output_file) click to toggle source
Calls superclass method
# File lib/expansions/file_merge.rb, line 26
def initialize(output_file)
  super
  @output_file = output_file
  @read_original_contents = true
end

Public Instance Methods

add_merge_file(items,file) click to toggle source
# File lib/expansions/file_merge.rb, line 60
def add_merge_file(items,file)
  return if items.include?(file)
  items << file if File.exists?(file)
end
dont_read_original_file_contents() click to toggle source
# File lib/expansions/file_merge.rb, line 32
def dont_read_original_file_contents
  @read_original_contents = false
end
merge_files(source_files,target) click to toggle source
# File lib/expansions/file_merge.rb, line 54
def merge_files(source_files,target)
  source_files.each do|source|
    write_contents(target,source) 
  end
end
run() click to toggle source
# File lib/expansions/file_merge.rb, line 36
def run
  copy_name = File.join(File.dirname(@output_file),"copy_of_#{File.basename(@output_file)}")
  FileUtils.cp @output_file, copy_name if File.exist?(@output_file)
  FileUtils.rm_f @output_file
  File.open_for_write(@output_file) do |file|
    merge_files(@before_files,file)
    write_contents(file,copy_name) if @read_original_contents && File.exist?(copy_name)
    merge_files(@after_files,file)
  end
  FileUtils.rm_f copy_name if File.exist?(copy_name)
end
write_contents(target_file_stream,file_to_read) click to toggle source
# File lib/expansions/file_merge.rb, line 48
def write_contents(target_file_stream,file_to_read)
  File.open_for_read(file_to_read) do|line|
    target_file_stream << line
  end
end