class ArchSpec::Rules::MustImplementRule
Backs ArchSpec::DSL::ComponentProxy#must_implement. Flags classes in the component that do not implement the method, counting inherited and mixed-in methods.
Attributes
Public Class Methods
# File lib/archspec/rules/protocol_rules.rb, line 89 def initialize(source, method_name, scope: :instance, arity: nil, keywords: nil) ProtocolEvidence.validate_scope!(scope, for_rule: 'must_implement') if arity && (!arity.is_a?(Integer) || arity.negative?) raise Error, "must_implement arity: must be a non-negative Integer, got #{arity.inspect}" end @source = source.to_sym @method_name = method_name.to_sym @scope = scope @arity = arity @keywords = Array(keywords).compact.map(&:to_sym).to_set end
Public Instance Methods
Source
# File lib/archspec/rules/protocol_rules.rb, line 110 def evaluate(graph) constants_for(graph).filter_map do |constant| definitions, unresolved = graph.effective_method_definitions(constant.name, scope) implementations = definitions.select { |definition| definition.name == method_name } next if requirement_met?(implementations) Diagnostic.new( rule: id, message: "#{constant.name} must implement #{method_label}#{requirement_clause}", location: constant.location, evidence: evidence_for(constant, definitions, implementations, unresolved), confidence: unresolved.empty? && signature_known?(implementations) ? :high : :medium ) end end
Source
# File lib/archspec/rules/protocol_rules.rb, line 106 def id 'protocol.must_implement' end
Source
# File lib/archspec/rules/protocol_rules.rb, line 102 def merge_key [self.class, source, method_name, scope, arity, keywords] end