Class: RailsCodeHealth::FileAnalyzer
- Inherits:
-
Object
- Object
- RailsCodeHealth::FileAnalyzer
- Defined in:
- lib/rails_code_health/file_analyzer.rb
Instance Method Summary collapse
- #analyze_all ⇒ Object
- #analyze_file(file_path) ⇒ Object
-
#initialize(project_path) ⇒ FileAnalyzer
constructor
A new instance of FileAnalyzer.
Constructor Details
#initialize(project_path) ⇒ FileAnalyzer
Returns a new instance of FileAnalyzer.
3 4 5 |
# File 'lib/rails_code_health/file_analyzer.rb', line 3 def initialize(project_path) @project_path = Pathname.new(project_path) end |
Instance Method Details
#analyze_all ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/rails_code_health/file_analyzer.rb', line 7 def analyze_all ruby_files = find_ruby_files view_files = find_view_files all_files = ruby_files + view_files all_files.map do |file_path| analyze_file(file_path) end.compact end |
#analyze_file(file_path) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rails_code_health/file_analyzer.rb', line 18 def analyze_file(file_path) file_path = Pathname.new(file_path) unless file_path.is_a?(Pathname) return nil unless file_path.exist? file_type = ProjectDetector.detect_file_type(file_path, @project_path) return nil unless file_type result = { file_path: file_path.to_s, relative_path: file_path.relative_path_from(@project_path).to_s, file_type: file_type, file_size: file_path.size, last_modified: file_path.mtime } # Analyze Ruby code if it's a Ruby file if file_path.extname == '.rb' ruby_analyzer = RubyAnalyzer.new(file_path) result[:ruby_analysis] = ruby_analyzer.analyze end # Add Rails-specific analysis rails_analyzer = RailsAnalyzer.new(file_path, file_type) rails_analysis = rails_analyzer.analyze result[:rails_analysis] = rails_analysis unless rails_analysis.empty? result rescue => e { file_path: file_path.to_s, relative_path: file_path.relative_path_from(@project_path).to_s, file_type: file_type, error: "Analysis failed: #{e.}" } end |