Module: Virtus::Attribute::Strict

Defined in:
lib/virtus/attribute/strict.rb

Overview

Attribute extension which raises CoercionError when coercion failed

Instance Method Summary collapse

Instance Method Details

#coerceObject

See Also:

  • Virtus::Attribute::Strict.[Attribute[Attribute#coerce]


13
14
15
16
17
18
19
20
21
# File 'lib/virtus/attribute/strict.rb', line 13

def coerce(*)
  output = super

  if value_coerced?(output) || !required? && output.nil?
    output
  else
    raise CoercionError.new(output, primitive)
  end
end