Exception: SmartParams::Error::InvalidPropertyType

Inherits:
SmartParams::Error show all
Defined in:
lib/smart_params/error/invalid_property_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keychain:, wanted:, raw:, missing_key: nil) ⇒ InvalidPropertyType

Returns a new instance of InvalidPropertyType.



11
12
13
14
15
16
17
# File 'lib/smart_params/error/invalid_property_type.rb', line 11

def initialize(keychain:, wanted:, raw:, missing_key: nil)
  super
  @keychain = keychain
  @wanted = wanted
  @raw = raw
  @missing_key = missing_key
end

Instance Attribute Details

#keychainObject (readonly)

Returns the value of attribute keychain.



6
7
8
# File 'lib/smart_params/error/invalid_property_type.rb', line 6

def keychain
  @keychain
end

#missing_keyObject (readonly)

Returns the value of attribute missing_key.



9
10
11
# File 'lib/smart_params/error/invalid_property_type.rb', line 9

def missing_key
  @missing_key
end

#rawObject (readonly)

Returns the value of attribute raw.



8
9
10
# File 'lib/smart_params/error/invalid_property_type.rb', line 8

def raw
  @raw
end

#wantedObject (readonly)

Returns the value of attribute wanted.



7
8
9
# File 'lib/smart_params/error/invalid_property_type.rb', line 7

def wanted
  @wanted
end

Instance Method Details

#as_jsonObject



27
28
29
30
31
32
33
# File 'lib/smart_params/error/invalid_property_type.rb', line 27

def as_json
  {
    "keychain" => keychain,
    "wanted" => wanted.name,
    "raw" => raw
  }
end

#messageObject



19
20
21
22
23
24
25
# File 'lib/smart_params/error/invalid_property_type.rb', line 19

def message
  if missing_key
    "expected #{keychain.inspect} to be #{wanted.name} with key #{missing_key.inspect}, but is #{raw.inspect}"
  else
    "expected #{keychain.inspect} to be #{wanted.name}, but is #{raw.inspect}"
  end
end