Class: ArchSpec::Rules::CannotInstantiateAndInvokeRule
- Inherits:
-
Object
- Object
- ArchSpec::Rules::CannotInstantiateAndInvokeRule
- Defined in:
- lib/archspec/rules/protocol_rules.rb
Overview
Backs ArchSpec::DSL::ComponentProxy#cannot_instantiate_and_invoke. Flags the one-shot Thing.new(...).call pattern.
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #evaluate(graph) ⇒ Object
- #id ⇒ Object
-
#initialize(source) ⇒ CannotInstantiateAndInvokeRule
constructor
A new instance of CannotInstantiateAndInvokeRule.
- #merge_key ⇒ Object
Constructor Details
#initialize(source) ⇒ CannotInstantiateAndInvokeRule
Returns a new instance of CannotInstantiateAndInvokeRule.
308 309 310 |
# File 'lib/archspec/rules/protocol_rules.rb', line 308 def initialize(source) @source = source.to_sym end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
306 307 308 |
# File 'lib/archspec/rules/protocol_rules.rb', line 306 def source @source end |
Instance Method Details
#evaluate(graph) ⇒ Object
320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/archspec/rules/protocol_rules.rb', line 320 def evaluate(graph) graph.edges.filter_map do |edge| next unless edge.type == :instantiates_and_invokes next unless graph.source_components_for(edge).include?(source) Diagnostic.new( rule: id, message: "#{source} must not instantiate and immediately invoke #{edge.to}", location: edge.location, evidence: "#{graph.edge_source_name(edge)} uses #{edge.to}" ) end end |
#id ⇒ Object
316 317 318 |
# File 'lib/archspec/rules/protocol_rules.rb', line 316 def id 'objects.instantiate_and_invoke_forbid' end |
#merge_key ⇒ Object
312 313 314 |
# File 'lib/archspec/rules/protocol_rules.rb', line 312 def merge_key [self.class, source] end |