Class: Thor::Shell::Basic

Inherits:
Object
  • Object
show all
Defined in:
lib/thorium/core/bootstrap.rb

Overview

Top level commit

Instance Method Summary collapse

Instance Method Details

#ask_filtered(statement, color, options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/thorium/core/bootstrap.rb', line 7

def ask_filtered(statement, color, options)
  answer_set = options[:limited_to]
  if options.key? :skip
    statement += if options[:skip].strip.empty?
      ' (Enter to skip)'
    else
      " (#{options[:skip]} to skip)"
    end
  end
  correct_answer answer_set, options, color, statement
end

#correct_answer(answer_set, options, color, statement) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/thorium/core/bootstrap.rb', line 19

def correct_answer(answer_set, options, color, statement)
  result = nil
  answers = answer_set.join(', ')
  statement += " [#{answers}]" unless options[:mute_limit_set]
  until result
    answer = ask_simply(statement, color, options)
    skipped = (options.key?(:skip) && (answer == options[:skip].chomp))
    result = answer_set.include?(answer) || skipped ? answer : nil
    unless result
      if options[:mute_limit_set]
        say('Your response is invalid. Please try again.')
      else
        say("Your response must be one of: [#{answers}]. Please try again.")
      end
    end
  end
  result
end