.vbw-planning/milestones/07-rails-audit-and-refactoring/03-controller-route-refactoring/05-PLAN.md
Replace the repetitive string-matching dispatch in ImportSessionsController#update with a handler registry pattern (C5), improving maintainability without changing behavior.
app/controllers/source_monitor/import_sessions_controller.rb:42-47 dispatches via 5 sequential if/return branchesshow (lines 34-37) with prepare_*_context methodsAdd to ImportSessionsController (near the top, after includes):
STEP_HANDLERS = {
"upload" => :handle_upload_step,
"preview" => :handle_preview_step,
"health_check" => :handle_health_check_step,
"configure" => :handle_configure_step,
"confirm" => :handle_confirm_step
}.freeze
Replace the 5 if/return branches in update with:
def update
handler = STEP_HANDLERS[@current_step]
return send(handler) if handler
# fallback for unknown steps (existing behavior)
@import_session.update!(session_attributes)
@current_step = target_step
@import_session.update_column(:current_step, @current_step) if @import_session.current_step != @current_step
redirect_to source_monitor.step_import_session_path(@import_session, step: @current_step), allow_other_host: false
end
Similarly, add a context preparation registry or simplify the show method:
STEP_CONTEXTS = {
"preview" => :prepare_preview_context,
"health_check" => :prepare_health_check_context,
"configure" => :prepare_configure_context,
"confirm" => :prepare_confirm_context
}.freeze
Then in show:
def show
context_method = STEP_CONTEXTS[@current_step]
send(context_method) if context_method
persist_step!
render :show
end
bin/rails test -- all pass (especially import_sessions_controller_test.rb)bin/rubocop -- zero offenses