lib/trace_location/generator/csv.rb in trace_location-0.4.0 vs lib/trace_location/generator/csv.rb in trace_location-0.9.0

- old
+ new

@@ -3,13 +3,14 @@ require 'csv' module TraceLocation module Generator class Csv < Base # :nodoc: + ATTRIBUTES = %w[id event path lineno caller_path caller_lineno method_str hierarchy].freeze + def initialize(events, return_value, options) - @events = events - @return_value = return_value + super @dest_dir = options.fetch(:dest_dir) { ::TraceLocation.config.dest_dir } @file_path = File.join(@dest_dir, "trace_location-#{Time.now.strftime('%Y%m%d%H%m%s')}.csv") end def generate @@ -26,12 +27,13 @@ FileUtils.mkdir_p(dest_dir) end def create_file CSV.open(file_path, 'wb+') do |csv| - csv << %w[event method path lineno] - events.each do |e| - csv << [e.event, e.method_str, e.path, e.lineno] + csv << ATTRIBUTES + + events.each do |event| + csv << ATTRIBUTES.map { |attr| event.public_send(attr) } end end end end end