Sha256: 6d73815e4f1dbde8916eaec1f608491063ad7999b35f7c78fd47bfab55a3df8c

Contents?: true

Size: 897 Bytes

Versions: 3

Compression:

Stored size: 897 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

3 entries across 3 versions & 1 rubygems

Version Path
gorails-0.1.5 vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb
gorails-0.1.4 vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb
gorails-0.1.3 vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb