Sha256: 8cece3f975c8ef8dc8c4fe4b370ca5cd0d6d496029a12bc36cffda006039c05b

Contents?: true

Size: 898 Bytes

Versions: 6

Compression:

Stored size: 898 Bytes

Contents

# typed: true

module CLI
  module UI
    module Prompt
      # A class that handles the various options of an InteractivePrompt and their callbacks
      class OptionsHandler
        extend T::Sig

        sig { void }
        def initialize
          @options = {}
        end

        sig { returns(T::Array[String]) }
        def options
          @options.keys
        end

        sig { params(option: String, handler: T.proc.params(option: String).returns(String)).void }
        def option(option, &handler)
          @options[option] = handler
        end

        sig { params(options: T.any(T::Array[String], String)).returns(String) }
        def call(options)
          case options
          when Array
            options.map { |option| @options[option].call(options) }
          else
            @options[options].call(options)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cli-ui-2.2.3 lib/cli/ui/prompt/options_handler.rb
cli-ui-2.2.2 lib/cli/ui/prompt/options_handler.rb
cli-ui-2.2.1 lib/cli/ui/prompt/options_handler.rb
cli-ui-2.2.0 lib/cli/ui/prompt/options_handler.rb
cli-ui-2.1.0 lib/cli/ui/prompt/options_handler.rb
cli-ui-2.0.0 lib/cli/ui/prompt/options_handler.rb