Class: TTY::Option::InvalidArgument

Inherits:
ParseError show all
Defined in:
lib/tty/option/errors.rb

Overview

Raised when parameter argument doesn’t match expected value

Constant Summary collapse

MESSAGE =
"value of `%<value>s` fails validation for '%<name>s' %<type>s"

Instance Attribute Summary

Attributes inherited from ParseError

#param

Instance Method Summary collapse

Methods inherited from ParseError

#format_value

Constructor Details

#initialize(param_or_message, value = nil) ⇒ InvalidArgument

Returns a new instance of InvalidArgument.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/tty/option/errors.rb', line 53

def initialize(param_or_message, value = nil)
  if param_or_message.is_a?(Parameter)
    @param = param_or_message

    message = format(MESSAGE,
                     value: format_value(value),
                     name: param.name,
                     type: param.to_sym)
  else
    message = param_or_message
  end

  super(message)
end