Exception: Constructor::ArgumentError

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

Overview

Fancy validation exception, based on missing and extraneous keys.

Instance Method Summary collapse

Constructor Details

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

:nodoc:#



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/constructor/constructor.rb', line 41

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