Class: Virtus::Coercer
- Inherits:
-
Object
- Object
- Virtus::Coercer
- Defined in:
- lib/virtus/coercer.rb
Overview
Abstract coercer class
Direct Known Subclasses
Attribute::Coercer, Attribute::EmbeddedValue::FromOpenStruct, Attribute::EmbeddedValue::FromStruct
Instance Attribute Summary collapse
- #primitive ⇒ Object readonly private
- #type ⇒ Object readonly private
Instance Method Summary collapse
-
#call(input) ⇒ Object
Coerce input value into expected primitive type.
-
#initialize(type) ⇒ Coercer
constructor
private
A new instance of Coercer.
-
#success?(primitive, input) ⇒ Object
Return if the input value was successfuly coerced.
Constructor Details
#initialize(type) ⇒ Coercer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Coercer.
12 13 14 15 |
# File 'lib/virtus/coercer.rb', line 12 def initialize(type) @type = type @primitive = type.primitive end |
Instance Attribute Details
#primitive ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/virtus/coercer.rb', line 9 def primitive @primitive end |
#type ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 |
# File 'lib/virtus/coercer.rb', line 9 def type @type end |
Instance Method Details
#call(input) ⇒ Object
Coerce input value into expected primitive type
24 25 26 |
# File 'lib/virtus/coercer.rb', line 24 def call(input) NotImplementedError.new("#{self.class}#call must be implemented") end |
#success?(primitive, input) ⇒ Object
Return if the input value was successfuly coerced
35 36 37 |
# File 'lib/virtus/coercer.rb', line 35 def success?(primitive, input) input.kind_of?(primitive) end |