Exception: Virtus::CoercionError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, attribute) ⇒ CoercionError

Returns a new instance of CoercionError.


16
17
18
19
# File 'lib/virtus.rb', line 16

def initialize(output, attribute)
  @output, @attribute = output, attribute
  super(build_message)
end

Instance Attribute Details

#attributeObject (readonly)


14
15
16
# File 'lib/virtus.rb', line 14

def attribute
  @attribute
end

#outputObject (readonly)


14
15
16
# File 'lib/virtus.rb', line 14

def output
  @output
end

Instance Method Details

#attribute_nameObject


29
30
31
# File 'lib/virtus.rb', line 29

def attribute_name
  attribute.options[:name]
end

#attribute_name?Boolean

Returns:

  • (Boolean)

33
34
35
# File 'lib/virtus.rb', line 33

def attribute_name?
  attribute_name ? true : false
end

#build_messageObject


21
22
23
24
25
26
27
# File 'lib/virtus.rb', line 21

def build_message
  if attribute_name?
    "Failed to coerce attribute `#{attribute_name}' from #{output.inspect} into #{target_type}"
  else
    "Failed to coerce #{output.inspect} into #{target_type}"
  end
end

#target_typeObject


37
38
39
# File 'lib/virtus.rb', line 37

def target_type
  attribute.primitive.inspect
end