Class: Packwerk::OffenseCollection
- Inherits:
-
Object
- Object
- Packwerk::OffenseCollection
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/packwerk/offense_collection.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#new_violations ⇒ Object
readonly
Returns the value of attribute new_violations.
-
#strict_mode_violations ⇒ Object
readonly
Returns the value of attribute strict_mode_violations.
Instance Method Summary collapse
- #add_offense(offense) ⇒ Object
- #add_offenses(offenses) ⇒ Object
-
#initialize(root_path, package_todos = {}) ⇒ OffenseCollection
constructor
A new instance of OffenseCollection.
- #listed?(offense) ⇒ Boolean
- #outstanding_offenses ⇒ Object
- #persist_package_todo_files(package_set) ⇒ Object
- #stale_violations?(for_files) ⇒ Boolean
- #unlisted_strict_mode_violations ⇒ Object
Constructor Details
#initialize(root_path, package_todos = {}) ⇒ OffenseCollection
Returns a new instance of OffenseCollection.
17 18 19 20 21 22 23 |
# File 'lib/packwerk/offense_collection.rb', line 17 def initialize(root_path, package_todos = {}) @root_path = root_path @package_todos = T.let(package_todos, T::Hash[Packwerk::Package, Packwerk::PackageTodo]) @new_violations = T.let([], T::Array[Packwerk::ReferenceOffense]) @strict_mode_violations = T.let([], T::Array[Packwerk::ReferenceOffense]) @errors = T.let([], T::Array[Packwerk::Offense]) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
29 30 31 |
# File 'lib/packwerk/offense_collection.rb', line 29 def errors @errors end |
#new_violations ⇒ Object (readonly)
Returns the value of attribute new_violations.
26 27 28 |
# File 'lib/packwerk/offense_collection.rb', line 26 def new_violations @new_violations end |
#strict_mode_violations ⇒ Object (readonly)
Returns the value of attribute strict_mode_violations.
32 33 34 |
# File 'lib/packwerk/offense_collection.rb', line 32 def strict_mode_violations @strict_mode_violations end |
Instance Method Details
#add_offense(offense) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/packwerk/offense_collection.rb', line 52 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
45 46 47 |
# File 'lib/packwerk/offense_collection.rb', line 45 def add_offenses(offenses) offenses.each { |offense| add_offense(offense) } end |
#listed?(offense) ⇒ Boolean
38 39 40 41 42 |
# File 'lib/packwerk/offense_collection.rb', line 38 def listed?(offense) return false unless offense.is_a?(ReferenceOffense) already_listed?(offense) end |
#outstanding_offenses ⇒ Object
84 85 86 |
# File 'lib/packwerk/offense_collection.rb', line 84 def outstanding_offenses errors + new_violations end |
#persist_package_todo_files(package_set) ⇒ Object
78 79 80 81 |
# File 'lib/packwerk/offense_collection.rb', line 78 def persist_package_todo_files(package_set) dump_package_todo_files cleanup_extra_package_todo_files(package_set) end |
#stale_violations?(for_files) ⇒ Boolean
71 72 73 74 75 |
# File 'lib/packwerk/offense_collection.rb', line 71 def stale_violations?(for_files) @package_todos.values.any? do |package_todo| package_todo.stale_violations?(for_files) end end |
#unlisted_strict_mode_violations ⇒ Object
89 90 91 |
# File 'lib/packwerk/offense_collection.rb', line 89 def unlisted_strict_mode_violations strict_mode_violations.reject { |offense| already_listed?(offense) } end |