Class: Rubyzen::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyzen/project.rb

Overview

Main entry point for analyzing a Ruby project. Parses all .rb files in the given paths and provides access to files, classes, and modules.

Examples:

Analyzing specific directories

project = Rubyzen::Project.new(["app/models", "app/controllers"])
project.files.with_paths("controllers/").classes

Using auto-discovery

project = Rubyzen::Project.new  # scans app/, lib/, src/, spec/
project.classes.with_name("UsersController")

Instance Method Summary collapse

Constructor Details

#initialize(paths = nil) ⇒ Project

Returns a new instance of Project.

Parameters:

  • paths (String, Array<String>, nil) (defaults to: nil)

    directories or file paths to analyze. Falls back to Configuration#project_paths (auto-discovery) if nil.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubyzen/project.rb', line 16

def initialize(paths = nil)
  paths ||= Rubyzen.configuration.project_paths
  @root_paths = Array(paths).map { |p| File.expand_path(p) }

  @root_paths.each do |path|
    unless File.exist?(path)
      raise Rubyzen::Error, "Path does not exist: #{path}"
    end
  end

  @file_paths = @root_paths.flat_map do |path|
    if File.directory?(path)
      Dir[File.join(path, '**', '*.rb')]
    else
      [path]
    end
  end.uniq

  @parser = Rubyzen::Parsers::ASTParser.instance
end

Instance Method Details

#classesCollections::ClassesCollection

Returns all classes found across all parsed files.



48
49
50
51
# File 'lib/rubyzen/project.rb', line 48

def classes
  all_classes = file_declarations.flat_map(&:classes)
  Collections::ClassesCollection.new(all_classes)
end

#filesCollections::FileCollection

Returns all parsed files as a filterable collection.



40
41
42
43
# File 'lib/rubyzen/project.rb', line 40

def files
  all_files = file_declarations
  Collections::FileCollection.new(all_files)
end

#modulesCollections::ModulesCollection

Returns all modules found across all parsed files.



56
57
58
59
# File 'lib/rubyzen/project.rb', line 56

def modules
  all_modules = file_declarations.flat_map(&:modules)
  Collections::ModulesCollection.new(all_modules)
end