Class: Formalism::Form::Coercion::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/formalism/form/coercion/_base.rb

Overview

Base class for coercion

Direct Known Subclasses

Array, Boolean, Class, Date, Hash, Numeric, Object, String, Symbol, Time

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/formalism/form/coercion/_base.rb', line 8

def initialize(value, *)
  @value = value

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

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

Instance Method Details

#resultObject



21
22
23
24
25
# File 'lib/formalism/form/coercion/_base.rb', line 21

def result
  return @value unless should_be_coreced?

  execute
end