Class: CheckstyleReports::Entity::FoundFile

Inherits:
Object
  • Object
show all
Defined in:
lib/checkstyle_reports/entity/found_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, prefix:) ⇒ FoundFile

Returns a new instance of FoundFile.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/checkstyle_reports/entity/found_file.rb', line 20

def initialize(node, prefix:)
  raise "Wrong node was passed. expected file but #{node.name}" if node.name != "file"

  if prefix.end_with?(file_separator)
    @prefix = prefix
  else
    @prefix = prefix + file_separator
  end

  name = node.attributes["name"]

  if Pathname.new(name).absolute?
    raise "Bad prefix was found for #{name}. #{@prefix} was a prefix." unless name.start_with?(@prefix)

    # Use delete_prefix when min support version becomes ruby 2.5
    @relative_path = name[@prefix.length, name.length - @prefix.length]
  else
    @relative_path = name
  end

  @path = @prefix + @relative_path

  @path = node.attributes["name"]
  @errors = []

  node.elements.each("error") { |n| @errors << FoundError.new(n) }
end

Instance Attribute Details

#errorsArray<FoundError> (readonly)

Errors which were detected in this file

Returns:



18
19
20
# File 'lib/checkstyle_reports/entity/found_file.rb', line 18

def errors
  @errors
end

#pathString (readonly)

A absolute path to this file

Returns:

  • (String)


8
9
10
# File 'lib/checkstyle_reports/entity/found_file.rb', line 8

def path
  @path
end

#relative_pathString (readonly)

A relative path to this file

Returns:

  • (String)


13
14
15
# File 'lib/checkstyle_reports/entity/found_file.rb', line 13

def relative_path
  @relative_path
end