Class: ArchSpec::Rules::CannotCallRule
- Inherits:
-
Object
- Object
- ArchSpec::Rules::CannotCallRule
- Defined in:
- lib/archspec/rules/protocol_rules.rb
Instance Attribute Summary collapse
-
#method_names ⇒ Object
readonly
Returns the value of attribute method_names.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #evaluate(graph) ⇒ Object
- #id ⇒ Object
-
#initialize(source, methods) ⇒ CannotCallRule
constructor
A new instance of CannotCallRule.
- #merge!(other) ⇒ Object
- #merge_key ⇒ Object
Constructor Details
#initialize(source, methods) ⇒ CannotCallRule
Returns a new instance of CannotCallRule.
6 7 8 9 |
# File 'lib/archspec/rules/protocol_rules.rb', line 6 def initialize(source, methods) @source = source.to_sym @method_names = Array(methods).flatten.map(&:to_sym) end |
Instance Attribute Details
#method_names ⇒ Object (readonly)
Returns the value of attribute method_names.
4 5 6 |
# File 'lib/archspec/rules/protocol_rules.rb', line 4 def method_names @method_names end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
4 5 6 |
# File 'lib/archspec/rules/protocol_rules.rb', line 4 def source @source end |
Instance Method Details
#evaluate(graph) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/archspec/rules/protocol_rules.rb', line 24 def evaluate(graph) graph.edges.filter_map do |edge| next unless edge.type == :calls_named_method next unless method_names.include?(edge.to.to_sym) next unless graph.component_names_for_path(edge.from_path).include?(source) Diagnostic.new( rule: id, message: "#{source} must not call ##{edge.to}", location: edge.location, evidence: "#{edge.from_constant || edge.from_path} calls #{edge.to}" ) end end |
#id ⇒ Object
20 21 22 |
# File 'lib/archspec/rules/protocol_rules.rb', line 20 def id "methods.forbid" end |
#merge!(other) ⇒ Object
15 16 17 18 |
# File 'lib/archspec/rules/protocol_rules.rb', line 15 def merge!(other) @method_names |= other.method_names self end |
#merge_key ⇒ Object
11 12 13 |
# File 'lib/archspec/rules/protocol_rules.rb', line 11 def merge_key [self.class, source] end |