Class: RspecLogFormatter::HistoryManager

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_log_formatter/history_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ HistoryManager

Returns a new instance of HistoryManager.



6
7
8
# File 'lib/rspec_log_formatter/history_manager.rb', line 6

def initialize(filepath)
  @filepath = filepath
end

Instance Method Details

#buildsObject



10
11
12
# 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

#resultsObject



29
30
31
32
33
# File 'lib/rspec_log_formatter/history_manager.rb', line 29

def results
  lines.map do |line|
    parse(line)
  end
end

#truncate(number_of_builds) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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