class Formalism::Form::Coercion::Base

Base class for coercion

Public Class Methods

new(value, *) click to toggle source
# File lib/formalism/form/coercion/_base.rb, line 8
def initialize(value, *)
        @value = value

        type_name = self.class.name.split('::')[3..-1].join('::')

        @type =
                if Object.const_defined?(type_name, false)
                then Object.const_get(type_name, false)
                else type_name
                end
end

Public Instance Methods

result() click to toggle source
# File lib/formalism/form/coercion/_base.rb, line 20
def result
        return @value unless should_be_coreced?

        execute
end

Private Instance Methods

should_be_coreced?() click to toggle source
# File lib/formalism/form/coercion/_base.rb, line 28
def should_be_coreced?
        @type != 'Base' && !(@type.is_a?(Class) && @value.is_a?(@type))
end