Class: ArchSpec::Rules::CannotCallRule

Inherits:
Object
  • Object
show all
Defined in:
lib/archspec/rules/protocol_rules.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_namesObject (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

#sourceObject (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

#idObject



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_keyObject



11
12
13
# File 'lib/archspec/rules/protocol_rules.rb', line 11

def merge_key
  [self.class, source]
end