Class: CLI::Mastermind::UserInterface::AsyncSpinners

Inherits:
UI::SpinGroup
  • Object
show all
Defined in:
lib/cli/mastermind/user_interface.rb

Overview

Implementation of CLI::UI::SpinGroup with that keeps track of the results from individual spinners.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAsyncSpinners

Returns a new instance of AsyncSpinners.



197
198
199
200
# File 'lib/cli/mastermind/user_interface.rb', line 197

def initialize
  @results = {}
  super
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



195
196
197
# File 'lib/cli/mastermind/user_interface.rb', line 195

def results
  @results
end

Instance Method Details

#await(title) {|spinner| ... } ⇒ Object

Waits for a block to execute while displaying a spinner.

Parameters:

  • title (String)

    the title to display

Yield Parameters:

  • spinner (CLI::UI::Spinner)


207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/cli/mastermind/user_interface.rb', line 207

def await(title)
  @results[title] = nil

  add(title) do |spinner|
    catch(:success) do
      msg = catch(:fail) do
        @results[title] = yield spinner
        throw :success
      end

      puts msg
      CLI::UI::Spinner::TASK_FAILED
    end
  end
end