Class: ArchSpec::Rules::CannotInstantiateAndInvokeRule

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) ⇒ CannotInstantiateAndInvokeRule

Returns a new instance of CannotInstantiateAndInvokeRule.



159
160
161
# File 'lib/archspec/rules/protocol_rules.rb', line 159

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

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



157
158
159
# File 'lib/archspec/rules/protocol_rules.rb', line 157

def source
  @source
end

Instance Method Details

#evaluate(graph) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/archspec/rules/protocol_rules.rb', line 171

def evaluate(graph)
  graph.edges.filter_map do |edge|
    next unless edge.type == :instantiates_and_invokes
    next unless graph.component_names_for_path(edge.from_path).include?(source)

    Diagnostic.new(
      rule: id,
      message: "#{source} must not instantiate and immediately invoke #{edge.to}",
      location: edge.location,
      evidence: "#{edge.from_constant || edge.from_path} uses #{edge.to}"
    )
  end
end

#idObject



167
168
169
# File 'lib/archspec/rules/protocol_rules.rb', line 167

def id
  "objects.instantiate_and_invoke_forbid"
end

#merge_keyObject



163
164
165
# File 'lib/archspec/rules/protocol_rules.rb', line 163

def merge_key
  [self.class, source]
end