Class: ArchSpec::Rules::MustImplementRule
- Inherits:
-
Object
- Object
- ArchSpec::Rules::MustImplementRule
- Defined in:
- lib/archspec/rules/protocol_rules.rb
Overview
Backs ArchSpec::DSL::ComponentProxy#must_implement. Flags classes in the component that do not implement the method, counting inherited and mixed-in methods.
Instance Attribute Summary collapse
-
#arity ⇒ Object
readonly
Returns the value of attribute arity.
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #evaluate(graph) ⇒ Object
- #id ⇒ Object
-
#initialize(source, method_name, scope: :instance, arity: nil, keywords: nil) ⇒ MustImplementRule
constructor
A new instance of MustImplementRule.
- #merge_key ⇒ Object
Constructor Details
#initialize(source, method_name, scope: :instance, arity: nil, keywords: nil) ⇒ MustImplementRule
Returns a new instance of MustImplementRule.
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/archspec/rules/protocol_rules.rb', line 88 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 |
Instance Attribute Details
#arity ⇒ Object (readonly)
Returns the value of attribute arity.
86 87 88 |
# File 'lib/archspec/rules/protocol_rules.rb', line 86 def arity @arity end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
86 87 88 |
# File 'lib/archspec/rules/protocol_rules.rb', line 86 def keywords @keywords end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
86 87 88 |
# File 'lib/archspec/rules/protocol_rules.rb', line 86 def method_name @method_name end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
86 87 88 |
# File 'lib/archspec/rules/protocol_rules.rb', line 86 def scope @scope end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
86 87 88 |
# File 'lib/archspec/rules/protocol_rules.rb', line 86 def source @source end |
Instance Method Details
#evaluate(graph) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/archspec/rules/protocol_rules.rb', line 109 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 |
#id ⇒ Object
105 106 107 |
# File 'lib/archspec/rules/protocol_rules.rb', line 105 def id 'protocol.must_implement' end |
#merge_key ⇒ Object
101 102 103 |
# File 'lib/archspec/rules/protocol_rules.rb', line 101 def merge_key [self.class, source, method_name, scope, arity, keywords] end |