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) || receiver.is_a?(String) raise Error, "cannot_call receiver: must be :any, :none or a constant name, got #{receiver.inspect}" end @source = source.to_sym @method_names = Array(methods).flatten.map(&:to_sym) @receiver = receiver.is_a?(String) ? receiver.sub(/\A::/, '') : 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 forbidden = forbidden_name(edge) next unless forbidden next if receiver == :none && edge.receiver != :none next if receiver.is_a?(String) && !receiver_matches?(graph, edge) next unless graph.source_components_for(edge).include?(source) next if own_method_call?(graph, edge) Diagnostic.new( rule: id, message: "#{source} must not call ##{forbidden}", location: edge.location, evidence: evidence_for(graph, edge) ) 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