lib/fukuzatsu/formatters/base.rb in fukuzatsu-0.9.16 vs lib/fukuzatsu/formatters/base.rb in fukuzatsu-0.10.1

- old
+ new

@@ -2,14 +2,16 @@ module Base def self.included(klass) klass.send(:attr_accessor, :file) + klass.send(:attr_accessor, :source) end - def initialize(file) + def initialize(file, source="") self.file = file + self.source = source end def content [header, rows, footer].flatten.join("\r\n") end @@ -21,34 +23,31 @@ def root_path "doc/fukuzatsu" end def output_path - output_path = "#{root_path}/#{self.file.path_to_file.split('/')[0..-2].join("/")}" + output_path = File.dirname(File.join(root_path, self.file.path_to_file)) FileUtils.mkpath(output_path) output_path end def path_to_results - "#{output_path}/#{filename}" + File.join(output_path, filename) end def filename - self.file.path_to_file.split('/')[-1] + file_extension + File.basename(self.file.path_to_file) + file_extension end def file_extension "" end def export begin - outfile = File.open("#{path_to_results}", 'w') - outfile.write(content) + File.open(path_to_results, 'w') {|outfile| outfile.write(content)} rescue Exception => e puts "Unable to write output: #{e} #{e.backtrace}" - ensure - outfile && outfile.close end end end