File: last_run.rb

package info (click to toggle)
ruby-simplecov 0.22.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,512 kB
  • sloc: ruby: 5,550; makefile: 10
file content (28 lines) | stat: -rw-r--r-- 556 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

require "json"

module SimpleCov
  module LastRun
    class << self
      def last_run_path
        File.join(SimpleCov.coverage_path, ".last_run.json")
      end

      def read
        return nil unless File.exist?(last_run_path)

        json = File.read(last_run_path)
        return nil if json.strip.empty?

        JSON.parse(json, symbolize_names: true)
      end

      def write(json)
        File.open(last_run_path, "w+") do |f|
          f.puts JSON.pretty_generate(json)
        end
      end
    end
  end
end