Class: ArchSpec::Rules::MustBeEmptyRule
- Inherits:
-
Object
- Object
- ArchSpec::Rules::MustBeEmptyRule
- Defined in:
- lib/archspec/rules/component_rules.rb
Overview
Backs ArchSpec::DSL::ComponentProxy#must_be_empty. Flags every file in a component that is meant to hold none.
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #evaluate(graph) ⇒ Object
- #id ⇒ Object
-
#initialize(source) ⇒ MustBeEmptyRule
constructor
A new instance of MustBeEmptyRule.
- #merge_key ⇒ Object
Constructor Details
#initialize(source) ⇒ MustBeEmptyRule
Returns a new instance of MustBeEmptyRule.
10 11 12 |
# File 'lib/archspec/rules/component_rules.rb', line 10 def initialize(source) @source = source.to_sym end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
8 9 10 |
# File 'lib/archspec/rules/component_rules.rb', line 8 def source @source end |
Instance Method Details
#evaluate(graph) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/archspec/rules/component_rules.rb', line 22 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: "#{source} must stay empty", location: SourceLocation.point(path, 1, 1), evidence: "#{relative} belongs to #{source}" ) end end |
#id ⇒ Object
18 19 20 |
# File 'lib/archspec/rules/component_rules.rb', line 18 def id 'components.empty' end |
#merge_key ⇒ Object
14 15 16 |
# File 'lib/archspec/rules/component_rules.rb', line 14 def merge_key [self.class, source] end |