class Thor
Public Instance Methods
ask_file_with_path(pattern, message_file_name)
click to toggle source
# File lib/viperaptor/cli/thor_extension.rb, line 33 def ask_file_with_path(pattern, message_file_name) project_files = Dir[pattern] count = project_files.count default_message = "The path to a #{message_file_name}:" if count == 1 is_right_path = yes?"The path to a #{message_file_name} is '#{project_files[0]}'. Do you want to use it? (yes/no)" xcode_path = is_right_path ? project_files[0] : ask(default_message) else xcode_path = ask(default_message) end return xcode_path end
ask_index(message, array)
click to toggle source
# File lib/viperaptor/cli/thor_extension.rb, line 6 def ask_index(message, array) value_index = ask_with_validation(message,->(value){ (value.to_i >= 0 and value.to_i < array.count) },"Invalid selection. Please enter number from 0 to #{array.count-1}") return array[value_index.to_i] end
ask_loop(message)
click to toggle source
# File lib/viperaptor/cli/thor_extension.rb, line 15 def ask_loop(message) array = Array.new loop do value = ask(message) break if value.empty? array.push(value) end return array end
ask_non_empty_string(message, description = 'Value should be nonempty string')
click to toggle source
# File lib/viperaptor/cli/thor_extension.rb, line 11 def ask_non_empty_string(message, description = 'Value should be nonempty string') return ask_with_validation(message,->(value){ value != nil && value.length > 0 },description) end
ask_with_validation(message, is_valid_value, description = 'Invalid value')
click to toggle source
# File lib/viperaptor/cli/thor_extension.rb, line 25 def ask_with_validation(message, is_valid_value, description = 'Invalid value') loop do value = ask(message) return value if is_valid_value.call(value) puts(description.red) end end