Class: RailsCodeHealth::RubyAnalyzer

Inherits:
Object
  • Object
show all
Includes:
ASTHelpers
Defined in:
lib/rails_code_health/ruby_analyzer.rb

Constant Summary

Constants included from ASTHelpers

ASTHelpers::SCOPE_BOUNDARY_TYPES, ASTHelpers::VISIBILITY_MODIFIERS

Instance Method Summary collapse

Methods included from ASTHelpers

#class_body_sends, #defs_by_visibility, #erb_ruby_fragments, #find_nodes, #find_nodes_in_scope

Constructor Details

#initialize(file_path) ⇒ RubyAnalyzer

Returns a new instance of RubyAnalyzer.



4
5
6
7
8
9
10
11
# File 'lib/rails_code_health/ruby_analyzer.rb', line 4

def initialize(file_path)
  @file_path = file_path
  @source = File.read(file_path)
  @ast = Parser::CurrentRuby.parse(@source)
rescue Parser::SyntaxError => e
  @parse_error = e
  @ast = nil
end

Instance Method Details

#analyzeObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rails_code_health/ruby_analyzer.rb', line 13

def analyze
  return { parse_error: @parse_error.message } if @parse_error

  {
    file_metrics: analyze_file,
    class_metrics: analyze_classes,
    method_metrics: analyze_methods,
    complexity_metrics: analyze_complexity,
    code_smells: detect_code_smells
  }
end