Class: TTY::Prompt::Question::Checks::CheckValidation

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/prompt/question/checks.rb

Overview

Check if input requires validation

Class Method Summary collapse

Class Method Details

.call(question, value) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/tty/prompt/question/checks.rb', line 53

def self.call(question, value)
  if !question.validation? || (question.required? && value.nil?) ||
    (question.validation? &&
      Validation.new(question.validation).call(value))
    [value]
  else
    tokens = { valid: question.validation.inspect, value: value }
    [value, question.message_for(:valid?, tokens)]
  end
end