module Mixture::Extensions::Coercable

Extends the attribute definition to allow coercion.

Public Class Methods

coerce_attribute(attribute, value) click to toggle source

Performs the coercion for the attribute and the value. It is used in a `:update` callback.

@see Coerce.perform @param attribute [Attribute] The attribute @param value [Object] The new value. @return [Object] The new new value. @raise [CoercionError] If an error occurs while a coercion is

running.
# File lib/mixture/extensions/coercable.rb, line 17
def self.coerce_attribute(attribute, value)
  return value unless attribute.options[:type]
  Coerce.perform(attribute.options[:type], value)
end
included(base) click to toggle source

Called by Ruby when the module is included.

@param base [Object] @return [void] @api private

# File lib/mixture/extensions/coercable.rb, line 27
def self.included(base)
  base.attributes.callbacks[:update] << method(:coerce_attribute)
end