Class: Clack::Prompts::Tasks
- Inherits:
-
Object
- Object
- Clack::Prompts::Tasks
- Defined in:
- lib/clack/prompts/tasks.rb
Overview
Sequential task runner with spinner animation.
Runs tasks in order, showing a spinner while each runs. Displays success/error status after each task completes.
Each task is a hash with:
-
:title- display title -
:task- Proc to execute (exceptions are caught).Optionally accepts a message-update callable to change the spinner message mid-execution. -
:enabled- optional boolean (default true). When false,the task is skipped entirely.
Defined Under Namespace
Classes: Task, TaskResult
Instance Attribute Summary collapse
-
#enabled ⇒ Boolean
readonly
Whether the task should run (default: true).
-
#error ⇒ String?
readonly
Error message if failed.
-
#status ⇒ Symbol
readonly
:success or :error.
-
#task ⇒ Proc
readonly
The task to execute.
-
#title ⇒ String
readonly
The task title.
Instance Method Summary collapse
-
#initialize(tasks:, output: $stdout) ⇒ Tasks
constructor
A new instance of Tasks.
-
#run ⇒ Array<TaskResult>
Run all tasks sequentially.
Constructor Details
#initialize(tasks:, output: $stdout) ⇒ Tasks
Returns a new instance of Tasks.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/clack/prompts/tasks.rb', line 68 def initialize(tasks:, output: $stdout) @tasks = tasks.map do |task_data| Task.new( title: task_data[:title], task: task_data[:task], enabled: task_data.fetch(:enabled, true) ) end @output = output @results = [] end |
Instance Attribute Details
#enabled ⇒ Boolean (readonly)
Returns whether the task should run (default: true).
54 |
# File 'lib/clack/prompts/tasks.rb', line 54 Task = Data.define(:title, :task, :enabled) |
#error ⇒ String? (readonly)
Returns error message if failed.
64 |
# File 'lib/clack/prompts/tasks.rb', line 64 TaskResult = Data.define(:title, :status, :error) |
#status ⇒ Symbol (readonly)
Returns :success or :error.
64 |
# File 'lib/clack/prompts/tasks.rb', line 64 TaskResult = Data.define(:title, :status, :error) |
#task ⇒ Proc (readonly)
Returns the task to execute.
54 |
# File 'lib/clack/prompts/tasks.rb', line 54 Task = Data.define(:title, :task, :enabled) |
#title ⇒ String (readonly)
Returns the task title.
54 |
# File 'lib/clack/prompts/tasks.rb', line 54 Task = Data.define(:title, :task, :enabled) |
Instance Method Details
#run ⇒ Array<TaskResult>
Run all tasks sequentially.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/clack/prompts/tasks.rb', line 83 def run @output.print Core::Cursor.hide @tasks.each do |task| next unless task.enabled run_task(task) end @results ensure begin @output.print Core::Cursor.show rescue IOError, SystemCallError # output stream already closed end end |