Add Rails engine with browser UI at /whetrails
Mounts a Rails engine that lists app models in a sidebar and renders the full callback/validator chain for any model. Source locations are linked via vscode:// URIs. Condition badges and concern module tags distinguish at-a-glance where each callback comes from. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
23
app/controllers/whetrails/application_controller.rb
Normal file
23
app/controllers/whetrails/application_controller.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
module Whetrails
|
||||
class ApplicationController < ActionController::Base
|
||||
layout "whetrails/application"
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
before_action :load_all_models
|
||||
|
||||
private
|
||||
|
||||
def load_all_models
|
||||
::Rails.application.eager_load!
|
||||
app_root = ::Rails.root.to_s
|
||||
@all_models = ::ActiveRecord::Base.descendants
|
||||
.reject(&:abstract_class?)
|
||||
.reject { |m| m.name.nil? }
|
||||
.select { |m|
|
||||
file = Object.const_source_location(m.name)&.first rescue nil
|
||||
file&.start_with?(app_root)
|
||||
}
|
||||
.sort_by(&:name)
|
||||
end
|
||||
end
|
||||
end
|
||||
16
app/controllers/whetrails/models_controller.rb
Normal file
16
app/controllers/whetrails/models_controller.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
module Whetrails
|
||||
class ModelsController < ApplicationController
|
||||
def index
|
||||
if @all_models.any?
|
||||
redirect_to model_path(@all_models.first.name)
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@model_class = params[:id].constantize
|
||||
@chain = ::Whetrails::Inspector.inspect_model(@model_class)
|
||||
rescue NameError
|
||||
head :not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user