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

Constructor Details

#initialize(param_or_message, value = nil) ⇒ InvalidArgument

Returns a new instance of InvalidArgument.


37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tty/option/errors.rb', line 37

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

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

  super(message)
end