class ArchSpec::Rules::MustImplementOneOfRule
Backs ArchSpec::DSL::ComponentProxy#must_implement_one_of. Flags classes that implement none of the named methods.
Attributes
Public Class Methods
# File lib/archspec/rules/protocol_rules.rb, line 186 def initialize(source, method_names, scope: :instance) ProtocolEvidence.validate_scope!(scope, for_rule: 'must_implement_one_of') @source = source.to_sym names = Array(method_names).flatten.compact raise Error, 'must_implement_one_of requires at least one method' if names.empty? @method_names = names.map(&:to_sym) @scope = scope end
Public Instance Methods
Source
# File lib/archspec/rules/protocol_rules.rb, line 209 def evaluate(graph) constants_for(graph).filter_map do |constant| methods, unresolved = if scope == :class graph.effective_class_methods(constant.name) else graph.effective_instance_methods(constant.name) end next if method_names.any? { |method_name| methods.include?(method_name) } sigil = scope == :class ? '.' : '#' choices = method_names.map { |name| "#{sigil}#{name}" }.join(', ') Diagnostic.new( rule: id, message: "#{constant.name} must implement one of #{choices}", location: constant.location, evidence: ProtocolEvidence.for(constant, methods, unresolved, scope: scope), confidence: unresolved.empty? ? :high : :medium ) end end
Source
# File lib/archspec/rules/protocol_rules.rb, line 205 def id 'protocol.must_implement_one_of' end
Source
# File lib/archspec/rules/protocol_rules.rb, line 200 def merge!(other) @method_names |= other.method_names self end
Source
# File lib/archspec/rules/protocol_rules.rb, line 196 def merge_key [self.class, source, scope] end