Class: ArchSpec::Rules::CannotCallRule
- Inherits:
-
Object
- Object
- ArchSpec::Rules::CannotCallRule
- Defined in:
- lib/archspec/rules/protocol_rules.rb
Overview
Backs ArchSpec::DSL::ComponentProxy#cannot_call. Flags calls to the named methods, optionally only bare implicit-+self+ calls.
Instance Attribute Summary collapse
-
#method_names ⇒ Object
readonly
Returns the value of attribute method_names.
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #evaluate(graph) ⇒ Object
- #id ⇒ Object
-
#initialize(source, methods, receiver: :any) ⇒ CannotCallRule
constructor
A new instance of CannotCallRule.
- #merge!(other) ⇒ Object
- #merge_key ⇒ Object
Constructor Details
#initialize(source, methods, receiver: :any) ⇒ CannotCallRule
Returns a new instance of CannotCallRule.
10 11 12 13 14 15 16 17 18 |
# File 'lib/archspec/rules/protocol_rules.rb', line 10 def initialize(source, methods, receiver: :any) unless %i[any none].include?(receiver) raise Error, "cannot_call receiver: must be :any or :none, got #{receiver.inspect}" end @source = source.to_sym @method_names = Array(methods).flatten.map(&:to_sym) @receiver = receiver end |
Instance Attribute Details
#method_names ⇒ Object (readonly)
Returns the value of attribute method_names.
8 9 10 |
# File 'lib/archspec/rules/protocol_rules.rb', line 8 def method_names @method_names end |
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
8 9 10 |
# File 'lib/archspec/rules/protocol_rules.rb', line 8 def receiver @receiver end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
8 9 10 |
# File 'lib/archspec/rules/protocol_rules.rb', line 8 def source @source end |
Instance Method Details
#evaluate(graph) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/archspec/rules/protocol_rules.rb', line 33 def evaluate(graph) graph.edges.filter_map do |edge| next unless edge.type == :calls_named_method next unless method_names.include?(edge.to.to_sym) next if receiver == :none && edge.receiver != :none next unless graph.component_names_for_path(edge.from_path).include?(source) next if own_method_call?(graph, edge) Diagnostic.new( rule: id, message: "#{source} must not call ##{edge.to}", location: edge.location, evidence: "#{edge.from_constant || edge.from_path} calls #{edge.to}" ) end end |
#id ⇒ Object
29 30 31 |
# File 'lib/archspec/rules/protocol_rules.rb', line 29 def id 'methods.forbid' end |
#merge!(other) ⇒ Object
24 25 26 27 |
# File 'lib/archspec/rules/protocol_rules.rb', line 24 def merge!(other) @method_names |= other.method_names self end |
#merge_key ⇒ Object
20 21 22 |
# File 'lib/archspec/rules/protocol_rules.rb', line 20 def merge_key [self.class, source, receiver] end |