Class: ArchSpec::Rules::AllowedConsumersRule
- Inherits:
-
Object
- Object
- ArchSpec::Rules::AllowedConsumersRule
- Defined in:
- lib/archspec/rules/dependency_rules.rb
Overview
Backs ArchSpec::DSL::ComponentProxy#can_only_be_used_by. The inverse of an allowlist: flags references to the component from any component that is not an approved consumer. Use it to protect a shared kernel.
Instance Attribute Summary collapse
-
#consumers ⇒ Object
readonly
Returns the value of attribute consumers.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #evaluate(graph) ⇒ Object
- #id ⇒ Object
-
#initialize(source, consumers) ⇒ AllowedConsumersRule
constructor
A new instance of AllowedConsumersRule.
- #merge!(other) ⇒ Object
- #merge_key ⇒ Object
Constructor Details
#initialize(source, consumers) ⇒ AllowedConsumersRule
Returns a new instance of AllowedConsumersRule.
88 89 90 91 |
# File 'lib/archspec/rules/dependency_rules.rb', line 88 def initialize(source, consumers) @source = source.to_sym @consumers = Array(consumers).flatten.map(&:to_sym).to_set end |
Instance Attribute Details
#consumers ⇒ Object (readonly)
Returns the value of attribute consumers.
86 87 88 |
# File 'lib/archspec/rules/dependency_rules.rb', line 86 def consumers @consumers end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
86 87 88 |
# File 'lib/archspec/rules/dependency_rules.rb', line 86 def source @source end |
Instance Method Details
#evaluate(graph) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/archspec/rules/dependency_rules.rb', line 106 def evaluate(graph) graph.dependency_edges.flat_map do |edge| next [] unless graph.target_components_for(edge).include?(source) offenders = graph.source_components_for(edge).reject do |component| component == source || consumers.include?(component) end offenders.map do |offender| Diagnostic.new( rule: id, message: (offender), location: edge.location, evidence: "#{graph.edge_source_name(edge)} #{edge.verb} #{edge.to}" ) end end end |
#id ⇒ Object
102 103 104 |
# File 'lib/archspec/rules/dependency_rules.rb', line 102 def id 'dependencies.consumers' end |
#merge!(other) ⇒ Object
97 98 99 100 |
# File 'lib/archspec/rules/dependency_rules.rb', line 97 def merge!(other) consumers.merge(other.consumers) self end |
#merge_key ⇒ Object
93 94 95 |
# File 'lib/archspec/rules/dependency_rules.rb', line 93 def merge_key [self.class, source] end |