Class: ArchSpec::Rules::MustImplementRule

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(source, method_name) ⇒ MustImplementRule

Returns a new instance of MustImplementRule.



68
69
70
71
# File 'lib/archspec/rules/protocol_rules.rb', line 68

def initialize(source, method_name)
  @source = source.to_sym
  @method_name = method_name.to_sym
end

Instance Attribute Details

#method_nameObject (readonly)

Returns the value of attribute method_name.



66
67
68
# File 'lib/archspec/rules/protocol_rules.rb', line 66

def method_name
  @method_name
end

#sourceObject (readonly)

Returns the value of attribute source.



66
67
68
# File 'lib/archspec/rules/protocol_rules.rb', line 66

def source
  @source
end

Instance Method Details

#evaluate(graph) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/archspec/rules/protocol_rules.rb', line 81

def evaluate(graph)
  constants_for(graph).filter_map do |constant|
    methods, unresolved = graph.effective_instance_methods(constant.name)
    next if methods.include?(method_name)

    Diagnostic.new(
      rule: id,
      message: "#{constant.name} must implement ##{method_name}",
      location: constant.location,
      evidence: ProtocolEvidence.for(constant, methods, unresolved),
      confidence: unresolved.empty? ? :high : :medium
    )
  end
end

#idObject



77
78
79
# File 'lib/archspec/rules/protocol_rules.rb', line 77

def id
  'protocol.must_implement'
end

#merge_keyObject



73
74
75
# File 'lib/archspec/rules/protocol_rules.rb', line 73

def merge_key
  [self.class, source, method_name]
end