Method: CommandMapper::Arg#validate

Defined in:
lib/command_mapper/arg.rb

#validate(value) ⇒ true, (false, String)

Validates whether a given value is compatible with the arg.

Parameters:

  • value (Object)

    The given value to validate.

Returns:

  • (true, (false, String))

    Returns true if the value is valid, or false and a validation error message if the value is not compatible.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/command_mapper/arg.rb', line 69

def validate(value)
  if value.nil?
    if required?
      return [false, "does not accept a nil value"]
    else
      return true
    end
  else
    return @type.validate(value)
  end
end