Module: RubynCode::Protocols::PlanApproval

Defined in:
lib/rubyn_code/protocols/plan_approval.rb

Overview

Presents a plan to the user for approval before executing significant changes.

This protocol ensures that destructive or wide-reaching operations are reviewed by a human before proceeding.

Constant Summary collapse

APPROVED =
:approved
REJECTED =
:rejected

Class Method Summary collapse

Class Method Details

.request(plan_text, prompt: nil) ⇒ Symbol

Displays a plan and asks the user to approve or reject it.

Parameters:

  • plan_text (String)

    the plan description to display

  • prompt (String, nil) (defaults to: nil)

    optional custom prompt message

Returns:

  • (Symbol)

    :approved or :rejected



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rubyn_code/protocols/plan_approval.rb', line 23

def request(plan_text, prompt: nil)
  pastel = Pastel.new
  display_plan(pastel, plan_text, prompt)

  approved = build_prompt.yes?(
    pastel.yellow.bold('Do you approve this plan?'),
    default: false
  )

  approved ? approve(pastel) : reject(pastel)
rescue TTY::Reader::InputInterrupt
  $stdout.puts pastel.red("\nPlan rejected (interrupted).")
  REJECTED
end