Module: AbideDevUtils::Prompt

Defined in:
lib/abide_dev_utils/prompt.rb

Class Method Summary collapse

Class Method Details

.passwordObject



31
32
33
# File 'lib/abide_dev_utils/prompt.rb', line 31

def self.password
  $stdin.getpass('Password:')
end

.secure(msg) ⇒ Object



35
36
37
# File 'lib/abide_dev_utils/prompt.rb', line 35

def self.secure(msg)
  $stdin.getpass(msg)
end

.single_line(msg, stream: $stdout) ⇒ Object



21
22
23
24
# File 'lib/abide_dev_utils/prompt.rb', line 21

def self.single_line(msg, stream: $stdout)
  AbideDevUtils::Output.print("#{msg}: ", stream: stream)
  $stdin.cooked(&:gets).chomp
end

.username(stream: $stdout) ⇒ Object



26
27
28
29
# File 'lib/abide_dev_utils/prompt.rb', line 26

def self.username(stream: $stdout)
  AbideDevUtils::Output.print('Username: ', stream: stream)
  $stdin.cooked(&:gets).chomp
end

.yes_no(msg, auto_approve: false, stream: $stdout) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/abide_dev_utils/prompt.rb', line 8

def self.yes_no(msg, auto_approve: false, stream: $stdout)
  prompt_msg = "#{msg} (Y/n): "
  if auto_approve
    AbideDevUtils::Output.simple("#{prompt_msg}Y", stream: stream)
    return true
  end

  AbideDevUtils::Output.print(prompt_msg, stream: stream)
  return true if $stdin.cooked(&:gets).match?(/^[Yy].*/)

  false
end