Class: Virtus::Attribute::Coercer Private
- Defined in:
- lib/virtus/attribute/coercer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Coercer accessor wrapper
Instance Attribute Summary collapse
- #coercers ⇒ Object readonly private
- #method ⇒ Object readonly private
Attributes inherited from Coercer
Instance Method Summary collapse
-
#call(value) ⇒ Object
private
Coerce given value.
-
#initialize(type, coercers) ⇒ undefined
constructor
private
Initialize a new coercer object.
- #success?(primitive, value) ⇒ Boolean
Constructor Details
#initialize(type, coercers) ⇒ undefined
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.
Initialize a new coercer object
20 21 22 23 24 |
# File 'lib/virtus/attribute/coercer.rb', line 20 def initialize(type, coercers) super(type) @method = type.coercion_method @coercers = coercers end |
Instance Attribute Details
#coercers ⇒ 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.
10 11 12 |
# File 'lib/virtus/attribute/coercer.rb', line 10 def coercers @coercers end |
#method ⇒ 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.
10 11 12 |
# File 'lib/virtus/attribute/coercer.rb', line 10 def method @method end |
Instance Method Details
#call(value) ⇒ Object
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.
Coerce given value
31 32 33 34 35 |
# File 'lib/virtus/attribute/coercer.rb', line 31 def call(value) coercers[value.class].public_send(method, value) rescue ::Coercible::UnsupportedCoercion value end |
#success?(primitive, value) ⇒ Boolean
38 39 40 |
# File 'lib/virtus/attribute/coercer.rb', line 38 def success?(primitive, value) coercers[primitive].coerced?(value) end |