Class: CC::CLI::Marker

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/cli/test.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, line_text) ⇒ Marker



63
64
65
66
67
# File 'lib/cc/cli/test.rb', line 63

def initialize(line, line_text)
  @line = line
  @line_text = line_text
  @issue = issue
end

Instance Attribute Details

#issueObject

Returns the value of attribute issue.



61
62
63
# File 'lib/cc/cli/test.rb', line 61

def issue
  @issue
end

#lineObject (readonly)

Returns the value of attribute line.



60
61
62
# File 'lib/cc/cli/test.rb', line 60

def line
  @line
end

#line_textObject (readonly)

Returns the value of attribute line_text.



60
61
62
# File 'lib/cc/cli/test.rb', line 60

def line_text
  @line_text
end

Class Method Details

.attrs_from_marker(text) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cc/cli/test.rb', line 29

def self.attrs_from_marker(text)
  if text.blank?
    {}
  else
    matches = text.scan(/([a-z\._-]+)=(?:(")((?:\\.|[^"])*)"|([^\s]*))/).map(&:compact)

    key_values = matches.map do |match|
      munge_match(match)
    end

    Hash[key_values]
  end
end

.from_text(engine_name, test_file, line_number, text) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cc/cli/test.rb', line 6

def self.from_text(engine_name, test_file, line_number, text)
  marker = Marker.new(line_number, text)
  attrs = attrs_from_marker(text.sub(/^.*\[issue\] ?/, ""))

  marker.issue = attrs.merge(
    "engine_name" => engine_name,
    "location" => {
      "path" => test_file,
      "lines" => {
        "begin" => line_number + 1,
        "end" => line_number + 1,
      },
    },
  )

  if marker.issue["category"]
    marker.issue["categories"] = Array.wrap(marker.issue["category"])
    marker.issue.delete("category")
  end

  marker
end

.munge_match(match) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/cc/cli/test.rb', line 43

def self.munge_match(match)
  if match.size == 3 # Quoted
    key, _, value = match
    value = '"' + value + '"'
  else
    key, value = match
  end

  [key, munge_value(value)]
end

.munge_value(value) ⇒ Object



54
55
56
57
58
# File 'lib/cc/cli/test.rb', line 54

def self.munge_value(value)
  JSON.load(value)
rescue JSON::ParserError
  value
end