class ArchSpec::Rules::CannotCallRule
Backs ArchSpec::DSL::ComponentProxy#cannot_call. Flags calls to the named methods, optionally only bare implicit-self calls.
Attributes
Public Class Methods
# 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
Public Instance Methods
Source
# 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
Source
# File lib/archspec/rules/protocol_rules.rb, line 24 def merge!(other) @method_names |= other.method_names self end
Source
# File lib/archspec/rules/protocol_rules.rb, line 20 def merge_key [self.class, source, receiver] end