10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/easy_app_helper/input.rb', line 10
def get_user_confirmation(choices: DEFAULT_CONFIRMATION_CHOICES,
default_choice: 'No',
prompt: 'Are you sure ?',
strict: false)
raise 'Invalid choices !' unless choices.is_a? Hash
values = choices.values.flatten
raise "Invalid default choice '#{default_choice}' !" unless values.include? default_choice
return true if EasyAppHelper.config[:auto]
full_prompt = '%s (%s): ' % [prompt, choices_string(values, default_choice)]
STDOUT.print full_prompt
STDOUT.flush
input = nil
until values.include? input
input = STDIN.gets.chomp
input = default_choice if input.nil? || input.empty?
unless strict
input = default_choice unless values.include? input
end
end
choices.each_pair do |res, possible_choices|
return res if possible_choices.include? input
end
raise 'Something wrong happened !'
end
|