Class: CLI::UI::Prompt::OptionsHandler
- Inherits:
-
Object
- Object
- CLI::UI::Prompt::OptionsHandler
- 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
- #call(options) ⇒ Object
-
#initialize ⇒ OptionsHandler
constructor
A new instance of OptionsHandler.
- #option(option, &handler) ⇒ Object
- #options ⇒ Object
Methods included from T::Sig
Constructor Details
#initialize ⇒ OptionsHandler
Returns a new instance of OptionsHandler.
11 12 13 |
# File 'lib/cli/ui/prompt/options_handler.rb', line 11 def initialize @options = {} end |
Instance Method Details
#call(options) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/cli/ui/prompt/options_handler.rb', line 26 def call() case when Array .map { |option| @options[option].call() } else @options[].call() end end |
#option(option, &handler) ⇒ Object
21 22 23 |
# File 'lib/cli/ui/prompt/options_handler.rb', line 21 def option(option, &handler) @options[option] = handler end |
#options ⇒ Object
16 17 18 |
# File 'lib/cli/ui/prompt/options_handler.rb', line 16 def @options.keys end |