Class: VisualModels::GraphController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- VisualModels::GraphController
- Defined in:
- app/controllers/visual_models/graph_controller.rb
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
5 6 7 8 9 10 |
# File 'app/controllers/visual_models/graph_controller.rb', line 5 def index @scopes = scope_labels @scope = @scopes.include?(params[:scope]) ? params[:scope] : @scopes.first @initial_graph = build_graph(@scope).to_json @title = VisualModels.config.title end |
#show ⇒ Object
12 13 14 15 16 17 18 |
# File 'app/controllers/visual_models/graph_controller.rb', line 12 def show scope = scope_labels.include?(params[:scope]) ? params[:scope] : scope_labels.first render json: build_graph(scope) rescue StandardError => e Rails.logger.error("[visual_models] #{e.class}: #{e.}\n#{e.backtrace&.first(5)&.join("\n")}") render json: { error: e. }, status: :unprocessable_entity end |
#source ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/visual_models/graph_controller.rb', line 20 def source raw = params[:path].to_s.strip raise ActionController::BadRequest, 'Missing path' if raw.blank? clean = Pathname.new(raw).cleanpath.to_s raise ActionController::BadRequest, 'Path traversal' if clean.start_with?('..') raise ActionController::BadRequest, 'Not a .rb file' unless clean.end_with?('.rb') abs = Rails.root.join(clean) raise ActionController::BadRequest, 'File not found' unless abs.file? render json: { source: abs.read, path: clean } rescue ActionController::BadRequest => e render json: { error: e. }, status: :bad_request rescue StandardError => e Rails.logger.error("[visual_models] source: #{e.class}: #{e.}") render json: { error: 'Failed to read file' }, status: :internal_server_error end |