Class: FastCov::TestMap::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/fast_cov/test_map/reader.rb

Overview

Reads a single sorted fragment file (gzipped or plain text). Merges consecutive entries with the same file path, which occur when multiple fragments are concatenated and sorted into an intermediate.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Reader

Returns a new instance of Reader.



13
14
15
16
17
18
19
20
# File 'lib/fast_cov/test_map/reader.rb', line 13

def initialize(path)
  @io = path.to_s.end_with?(".gz") ? Zlib::GzipReader.open(path) : File.open(path)
  @exhausted = false
  @next_file_path = nil
  @next_dependencies = nil
  read_line
  advance
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



11
12
13
# File 'lib/fast_cov/test_map/reader.rb', line 11

def dependencies
  @dependencies
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



11
12
13
# File 'lib/fast_cov/test_map/reader.rb', line 11

def file_path
  @file_path
end

Instance Method Details

#advanceObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fast_cov/test_map/reader.rb', line 26

def advance
  if @next_file_path.nil?
    @exhausted = true
    @file_path = nil
    @dependencies = []
    return
  end

  @file_path = @next_file_path
  @dependencies = @next_dependencies
  read_line

  # Merge consecutive lines with the same file path
  while @next_file_path == @file_path
    @dependencies.concat(@next_dependencies)
    read_line
  end
end

#closeObject



45
46
47
# File 'lib/fast_cov/test_map/reader.rb', line 45

def close
  @io.close
end

#exhausted?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/fast_cov/test_map/reader.rb', line 22

def exhausted?
  @exhausted
end