Exception: ConstructorArgumentError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/constructor.rb

Overview

Fancy validation exception, based on missing and extraneous keys.

Instance Method Summary collapse

Constructor Details

#initialize(missing, rejected = []) ⇒ ConstructorArgumentError

:nodoc:#



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/constructor.rb', line 110

def initialize(missing,rejected=[])
  err_msg = ''
  if missing.size > 0
    err_msg = "Missing constructor args [#{missing.join(',')}]"
  end
  if rejected.size > 0
    # Some inbound keys were not addressed earlier; this means they're unwanted
    if err_msg
      err_msg << "; " # Appending to earlier message about missing items
    else
      err_msg = ''
    end
    # Enumerate the rejected key names
    err_msg << "Rejected constructor args [#{rejected.join(',')}]"
  end
  super err_msg
end