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.



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

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

#idObject



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_keyObject



13
14
15
# File 'lib/archspec/rules/protocol_rules.rb', line 13

def merge_key
  [self.class, source]
end