Class: ArchSpec::Rules::MustBeEmptyRule

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, because: nil) ⇒ MustBeEmptyRule

Returns a new instance of MustBeEmptyRule.



8
9
10
11
# File 'lib/archspec/rules/component_rules.rb', line 8

def initialize(source, because: nil)
  @source = source.to_sym
  @because = because
end

Instance Attribute Details

#becauseObject (readonly)

Returns the value of attribute because.



6
7
8
# File 'lib/archspec/rules/component_rules.rb', line 6

def because
  @because
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/archspec/rules/component_rules.rb', line 6

def source
  @source
end

Instance Method Details

#evaluate(graph) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/archspec/rules/component_rules.rb', line 21

def evaluate(graph)
  component = graph.components[source]
  return [] unless component

  component.files.sort.map do |path|
    relative = graph.files[path]&.relative_path || path

    Diagnostic.new(
      rule: id,
      message: because ? "#{source} must stay empty: #{because}" : "#{source} must stay empty",
      location: SourceLocation.new(path, 1, 1),
      evidence: "#{relative} belongs to #{source}"
    )
  end
end

#idObject



17
18
19
# File 'lib/archspec/rules/component_rules.rb', line 17

def id
  'components.empty'
end

#merge_keyObject



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

def merge_key
  [self.class, source]
end