-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alexandre Terrasa <[email protected]>
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
|
||
require "spoom" | ||
|
||
# Collect all the files | ||
warn "Collecting files..." | ||
files = ARGV.flat_map do |path| | ||
if File.directory?(path) | ||
Dir.glob(File.join(path, "**/*.rb")).sort | ||
else | ||
path | ||
end | ||
end | ||
warn " Collected #{files.size} files" | ||
|
||
# Build the model | ||
warn "Building the model..." | ||
model = Spoom::Model.new | ||
|
||
files.each do |file| | ||
content = File.read(file) | ||
node = Spoom.parse_ruby(content, file: file) | ||
builder = Spoom::Model::Builder.new(model, file) | ||
builder.visit(node) | ||
rescue Spoom::ParseError | ||
# no-op | ||
end | ||
warn " Found #{model.symbols.size} symbols" | ||
|
||
# Collect all the references | ||
warn "Collecting references..." | ||
refs = T.let({}, T::Hash[String, T::Array[Spoom::Model::Reference]]) | ||
files.each do |file| | ||
content = File.read(file) | ||
node = Spoom.parse_ruby(content, file: file) | ||
visitor = Spoom::Model::ReferencesVisitor.new(file) | ||
visitor.visit(node) | ||
|
||
visitor.references.each do |ref| | ||
(refs[ref.name] ||= []) << ref | ||
end | ||
rescue Spoom::ParseError | ||
# no-op | ||
end | ||
warn " Found #{refs.size} references" | ||
|
||
# Collect all subclasses of `ApplicationController` | ||
warn "Collecting subclasses of ApplicationController..." | ||
model.finalize! | ||
symbol = model["ApplicationController"] | ||
subclasses = model.subtypes(symbol) | ||
warn " Found #{subclasses.size} subclasses" | ||
warn "\n\n" | ||
|
||
puts "Subclasses of ApplicationController:" | ||
subclasses.each do |subclass| | ||
puts " #{subclass.name}" | ||
subclass.definitions.each do |defn| | ||
next unless defn.is_a?(Spoom::Model::Class) | ||
|
||
defn.children.each do |child| | ||
next unless child.is_a?(Spoom::Model::Method) | ||
|
||
puts " #{child.name} - #{child.location} (#{refs[child.name]&.size || 0} refs)" | ||
end | ||
end | ||
end |