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.
11 12 13 14 |
# File 'lib/virtus/coercer.rb', line 11 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.
8 9 10 |
# File 'lib/virtus/coercer.rb', line 8 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.
8 9 10 |
# File 'lib/virtus/coercer.rb', line 8 def type @type end |
Instance Method Details
#call(input) ⇒ Object
Coerce input value into expected primitive type
23 24 25 |
# File 'lib/virtus/coercer.rb', line 23 def call(input) NotImplementedError.new("#{self.class}#call must be implemented") end |
#success?(primitive, input) ⇒ Object
Return if the input value was successfuly coerced
34 35 36 |
# File 'lib/virtus/coercer.rb', line 34 def success?(primitive, input) input.kind_of?(primitive) end |