Module: MetzScan::Analyzers::PackageMap

Defined in:
lib/metz_scan/analyzers/package_map.rb

Overview

Classifies coarse project packages used by index-backed project analyzers.

Class Method Summary collapse

Class Method Details

.app_index(parts) ⇒ Object



64
65
66
# File 'lib/metz_scan/analyzers/package_map.rb', line 64

def app_index(parts)
  parts.rindex("app")
end

.ignored_lib_package?(parts) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
# File 'lib/metz_scan/analyzers/package_map.rb', line 50

def ignored_lib_package?(parts)
  index = project_root_index(parts)
  return false unless index && parts[index] == "lib"

  index && IGNORED_LIB_PACKAGES.include?(parts[index + 1])
end

.ignored_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/metz_scan/analyzers/package_map.rb', line 22

def ignored_path?(path)
  parts = path.to_s.split(File::SEPARATOR)
  ignored_reference_root?(parts) || ignored_lib_package?(parts) || ignored_support_segment?(parts)
end

.ignored_reference_root?(parts) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/metz_scan/analyzers/package_map.rb', line 45

def ignored_reference_root?(parts)
  index = project_root_index(parts)
  index && IGNORED_REFERENCE_ROOTS.include?(parts[index])
end

.ignored_support_segment?(parts) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
# File 'lib/metz_scan/analyzers/package_map.rb', line 57

def ignored_support_segment?(parts)
  index = app_index(parts) || lib_index(parts)
  return false unless index

  parts[(index + 1)..].any? { |part| IGNORED_SUPPORT_SEGMENTS.include?(part) }
end

.lib_index(parts) ⇒ Object



68
69
70
# File 'lib/metz_scan/analyzers/package_map.rb', line 68

def lib_index(parts)
  parts.rindex("lib")
end

.package_after(parts, index) ⇒ Object



39
40
41
42
43
# File 'lib/metz_scan/analyzers/package_map.rb', line 39

def package_after(parts, index)
  return unless parts[index + 1]

  "#{parts[index]}/#{parts[index + 1]}"
end

.package_for(path) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/metz_scan/analyzers/package_map.rb', line 14

def package_for(path)
  parts = path.to_s.split(File::SEPARATOR)
  return package_after(parts, app_index(parts)) if app_index(parts)
  return package_after(parts, lib_index(parts)) if lib_index(parts)

  nil
end

.package_parts(path) ⇒ Object



35
36
37
# File 'lib/metz_scan/analyzers/package_map.rb', line 35

def package_parts(path)
  package_for(path).to_s.split("/")
end

.parts_after_package(path) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/metz_scan/analyzers/package_map.rb', line 27

def parts_after_package(path)
  parts = path.to_s.split(File::SEPARATOR)
  index = app_index(parts) || lib_index(parts)
  return [] unless index

  parts[(index + 2)..] || []
end

.project_root?(part) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/metz_scan/analyzers/package_map.rb', line 76

def project_root?(part)
  part == "app" || part == "lib" || IGNORED_REFERENCE_ROOTS.include?(part)
end

.project_root_index(parts) ⇒ Object



72
73
74
# File 'lib/metz_scan/analyzers/package_map.rb', line 72

def project_root_index(parts)
  parts.each_index.reverse_each.find { |index| project_root?(parts[index]) }
end