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.
8 9 10 11 |
# File 'lib/archspec/rules/protocol_rules.rb', line 8 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.
6 7 8 |
# File 'lib/archspec/rules/protocol_rules.rb', line 6 def method_names @method_names end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/archspec/rules/protocol_rules.rb', line 6 def source @source end |
Instance Method Details
#evaluate(graph) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/archspec/rules/protocol_rules.rb', line 26 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
22 23 24 |
# File 'lib/archspec/rules/protocol_rules.rb', line 22 def id 'methods.forbid' end |
#merge!(other) ⇒ Object
17 18 19 20 |
# File 'lib/archspec/rules/protocol_rules.rb', line 17 def merge!(other) @method_names |= other.method_names self end |
#merge_key ⇒ Object
13 14 15 |
# File 'lib/archspec/rules/protocol_rules.rb', line 13 def merge_key [self.class, source] end |