Module: Mixture::Extensions::Coercable
- Defined in:
- lib/mixture/extensions/coercable.rb
Overview
Extends the attribute definition to allow coercion.
Class Method Summary collapse
-
.coerce_attribute(attribute, value) ⇒ Object
Performs the coercion for the attribute and the value.
-
.included(base) ⇒ void
private
Called by Ruby when the module is included.
Class Method Details
.coerce_attribute(attribute, value) ⇒ Object
Performs the coercion for the attribute and the value.
It is used in a :update
callback.
17 18 19 20 |
# File 'lib/mixture/extensions/coercable.rb', line 17 def self.coerce_attribute(attribute, value) return value unless attribute.[:type] Coerce.perform(attribute.[:type], value) end |
.included(base) ⇒ void
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.
This method returns an undefined value.
Called by Ruby when the module is included.
27 28 29 |
# File 'lib/mixture/extensions/coercable.rb', line 27 def self.included(base) base.attributes.callbacks[:update] << method(:coerce_attribute) end |