Exception: SafeType::CoercionError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/safe_type/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, desired_type, key = nil) ⇒ CoercionError

Returns a new instance of CoercionError.



8
9
10
11
12
13
14
15
# File 'lib/safe_type/errors.rb', line 8

def initialize(value, desired_type, key=nil)
  super("Could not coerce " + (key.nil? ? '' : "key (#{key}) with ")  +
        "value (#{value.inspect}) of type (#{value.class}) to desired type (#{desired_type})")

  @key = key
  @value = value
  @desired_type = desired_type
end

Instance Attribute Details

#desired_typeObject (readonly)

Returns the value of attribute desired_type.



6
7
8
# File 'lib/safe_type/errors.rb', line 6

def desired_type
  @desired_type
end

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/safe_type/errors.rb', line 4

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/safe_type/errors.rb', line 5

def value
  @value
end