Class: Packwerk::OffenseCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/packwerk/offense_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path, package_todos = {}) ⇒ OffenseCollection

: (String root_path, ?Hash[Packwerk::Package, Packwerk::PackageTodo] package_todos) -> void



9
10
11
12
13
14
15
# File 'lib/packwerk/offense_collection.rb', line 9

def initialize(root_path, package_todos = {})
  @root_path = root_path
  @package_todos = package_todos #: Hash[Packwerk::Package, Packwerk::PackageTodo]
  @new_violations = [] #: Array[Packwerk::ReferenceOffense]
  @strict_mode_violations = [] #: Array[Packwerk::ReferenceOffense]
  @errors = [] #: Array[Packwerk::Offense]
end

Instance Attribute Details

#errorsObject (readonly)

: Array



21
22
23
# File 'lib/packwerk/offense_collection.rb', line 21

def errors
  @errors
end

#new_violationsObject (readonly)

: Array



18
19
20
# File 'lib/packwerk/offense_collection.rb', line 18

def new_violations
  @new_violations
end

#strict_mode_violationsObject (readonly)

: Array



24
25
26
# File 'lib/packwerk/offense_collection.rb', line 24

def strict_mode_violations
  @strict_mode_violations
end

Instance Method Details

#add_offense(offense) ⇒ Object

: (Packwerk::Offense offense) -> void



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/packwerk/offense_collection.rb', line 39

def add_offense(offense)
  unless offense.is_a?(ReferenceOffense)
    @errors << offense
    return
  end

  already_listed = already_listed?(offense)

  new_violations << offense unless already_listed

  if strict_mode_violation?(offense)
    add_to_package_todo(offense) if already_listed
    strict_mode_violations << offense
  else
    add_to_package_todo(offense)
  end
end

#add_offenses(offenses) ⇒ Object

: (Array offenses) -> void



34
35
36
# File 'lib/packwerk/offense_collection.rb', line 34

def add_offenses(offenses)
  offenses.each { |offense| add_offense(offense) }
end

#listed?(offense) ⇒ Boolean

: (Packwerk::Offense offense) -> bool

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/packwerk/offense_collection.rb', line 27

def listed?(offense)
  return false unless offense.is_a?(ReferenceOffense)

  already_listed?(offense)
end

#outstanding_offensesObject

: -> Array



71
72
73
# File 'lib/packwerk/offense_collection.rb', line 71

def outstanding_offenses
  errors + new_violations
end

#persist_package_todo_files(package_set) ⇒ Object

: (Packwerk::PackageSet package_set) -> void



65
66
67
68
# File 'lib/packwerk/offense_collection.rb', line 65

def persist_package_todo_files(package_set)
  dump_package_todo_files
  cleanup_extra_package_todo_files(package_set)
end

#stale_violations?(for_files) ⇒ Boolean

: (Set for_files) -> bool

Returns:

  • (Boolean)


58
59
60
61
62
# File 'lib/packwerk/offense_collection.rb', line 58

def stale_violations?(for_files)
  @package_todos.values.any? do |package_todo|
    package_todo.stale_violations?(for_files)
  end
end

#unlisted_strict_mode_violationsObject

: -> Array



76
77
78
# File 'lib/packwerk/offense_collection.rb', line 76

def unlisted_strict_mode_violations
  strict_mode_violations.reject { |offense| already_listed?(offense) }
end