Class: CLI::UI::Prompt::OptionsHandler

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/cli/ui/prompt/options_handler.rb

Overview

A class that handles the various options of an InteractivePrompt and their callbacks

Instance Method Summary collapse

Methods included from T::Sig

sig

Constructor Details

#initializeOptionsHandler

Returns a new instance of OptionsHandler.



12
13
14
# File 'lib/cli/ui/prompt/options_handler.rb', line 12

def initialize
  @options = {}
end

Instance Method Details

#call(options) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/cli/ui/prompt/options_handler.rb', line 27

def call(options)
  case options
  when Array
    options.map { |option| @options[option].call(options) }
  else
    @options[options].call(options)
  end
end

#option(option, &handler) ⇒ Object



22
23
24
# File 'lib/cli/ui/prompt/options_handler.rb', line 22

def option(option, &handler)
  @options[option] = handler
end

#optionsObject



17
18
19
# File 'lib/cli/ui/prompt/options_handler.rb', line 17

def options
  @options.keys
end