class RspecLogFormatter::HistoryManager

Public Class Methods

new(filepath) click to toggle source
# File lib/rspec_log_formatter/history_manager.rb, line 6
def initialize(filepath)
  @filepath = filepath
end

Public Instance Methods

builds() click to toggle source
# File lib/rspec_log_formatter/history_manager.rb, line 10
def builds
  results.map{|r| r.build_number.to_i}.reduce(SortedSet.new, &:<<).to_a
end
results() click to toggle source
# File lib/rspec_log_formatter/history_manager.rb, line 29
def results
  lines.map do |line|
    parse(line)
  end
end
truncate(number_of_builds) click to toggle source
# File lib/rspec_log_formatter/history_manager.rb, line 14
def truncate(number_of_builds)
  kept_builds = builds.to_a.last(number_of_builds)
  sio = StringIO.new

  lines.each do |line|
    sio.puts line if kept_builds.include? (parse(line).build_number.to_i)
  end

  sio.rewind

  File.open(@filepath, 'w') do |f|
    f.write sio.read
  end
end

Private Instance Methods

lines() click to toggle source
# File lib/rspec_log_formatter/history_manager.rb, line 42
def lines
  File.open(@filepath, 'r').lazy
end
parse(line) click to toggle source
# File lib/rspec_log_formatter/history_manager.rb, line 37
def parse(line)
  RspecLogFormatter::Analysis::Result.new(*CSV.parse_line(line, col_sep: "\t").first(8))
end