Class: RailsInteractive::CLI::Prompt

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/prompt.rb

Overview

Prompt class for commands

Instance Method Summary collapse

Constructor Details

#initialize(msg, type, options = nil, required: false) ⇒ Interactive::Prompt

Create a new instance

Parameters:

  • msg (String)

    the message to display

  • type (String)

    the type of prompt

  • options (Array) (defaults to: nil)

    the options to display

  • required (Boolean) (defaults to: false)

    whether the prompt value is required



17
18
19
20
21
22
23
# File 'lib/cli/prompt.rb', line 17

def initialize(msg, type, options = nil, required: false)
  @msg = msg
  @type = type
  @options = options
  @required = required
  @prompt = TTY::Prompt.new
end

Instance Method Details

#performString

Perform the prompt

Returns:

  • (String)

    the value of the prompt



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cli/prompt.rb', line 28

def perform
  case @type
  when "ask"
    @prompt.ask(@msg, required: @required)
  when "select"
    @prompt.select(@msg, @options, required: @required)
  when "multi_select"
    @prompt.multi_select(@msg, @options)
  else
    puts "Invalid parameter"
  end
end