Class: LayerChecker::CodeAnalyzer
- Inherits:
-
Object
- Object
- LayerChecker::CodeAnalyzer
- Defined in:
- lib/layer_checker/code_analyzer.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#file_dependencies ⇒ Object
readonly
Returns the value of attribute file_dependencies.
-
#project_root ⇒ Object
readonly
Returns the value of attribute project_root.
Instance Method Summary collapse
-
#analyze ⇒ Object
Scan all Ruby files in the project.
-
#files_for_module(mod) ⇒ Object
Get all files that belong to a specific module.
-
#initialize(config, project_root: Dir.pwd) ⇒ CodeAnalyzer
constructor
A new instance of CodeAnalyzer.
-
#unassigned_files ⇒ Object
Get files that don’t belong to any module.
Constructor Details
#initialize(config, project_root: Dir.pwd) ⇒ CodeAnalyzer
Returns a new instance of CodeAnalyzer.
9 10 11 12 13 |
# File 'lib/layer_checker/code_analyzer.rb', line 9 def initialize(config, project_root: Dir.pwd) @config = config @project_root = project_root @file_dependencies = {} end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/layer_checker/code_analyzer.rb', line 7 def config @config end |
#file_dependencies ⇒ Object (readonly)
Returns the value of attribute file_dependencies.
7 8 9 |
# File 'lib/layer_checker/code_analyzer.rb', line 7 def file_dependencies @file_dependencies end |
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
7 8 9 |
# File 'lib/layer_checker/code_analyzer.rb', line 7 def project_root @project_root end |
Instance Method Details
#analyze ⇒ Object
Scan all Ruby files in the project
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/layer_checker/code_analyzer.rb', line 16 def analyze ruby_files = find_ruby_files ruby_files.each do |file_path| relative_path = file_path.sub("#{@project_root}/", '') dependencies = DependencyExtractor.extract(file_path) @file_dependencies[relative_path] = { absolute_path: file_path, module: @config.module_for_file(relative_path), dependencies: dependencies } end @file_dependencies end |
#files_for_module(mod) ⇒ Object
Get all files that belong to a specific module
34 35 36 |
# File 'lib/layer_checker/code_analyzer.rb', line 34 def files_for_module(mod) @file_dependencies.select { |_, info| info[:module] == mod } end |
#unassigned_files ⇒ Object
Get files that don’t belong to any module
39 40 41 |
# File 'lib/layer_checker/code_analyzer.rb', line 39 def unassigned_files @file_dependencies.select { |_, info| info[:module].nil? } end |