Class: LayerChecker::DependencyValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/layer_checker/dependency_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, analyzer) ⇒ DependencyValidator

Returns a new instance of DependencyValidator.



9
10
11
12
13
# File 'lib/layer_checker/dependency_validator.rb', line 9

def initialize(config, analyzer)
  @config = config
  @analyzer = analyzer
  @violations = []
end

Instance Attribute Details

#analyzerObject (readonly)

Returns the value of attribute analyzer.



7
8
9
# File 'lib/layer_checker/dependency_validator.rb', line 7

def analyzer
  @analyzer
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/layer_checker/dependency_validator.rb', line 7

def config
  @config
end

#violationsObject (readonly)

Returns the value of attribute violations.



7
8
9
# File 'lib/layer_checker/dependency_validator.rb', line 7

def violations
  @violations
end

Instance Method Details

#validateObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/layer_checker/dependency_validator.rb', line 15

def validate
  @violations = []

  @analyzer.file_dependencies.each do |file_path, file_info|
    source_module = file_info[:module]
    
    # Handle unassigned files
    if source_module.nil?
      handle_unassigned_file(file_path, file_info)
      next
    end

    # Check each dependency
    file_info[:dependencies].each do |dependency|
      check_dependency(file_path, source_module, dependency)
    end
  end

  # Deduplicate violations (same file, line, source and target)
  @violations.uniq! do |v|
    [v.source_file, v.line_number, v.source_module&.full_name, v.target_module&.full_name]
  end

  @violations
end