Module: Structural::Model::TypeCasts

Defined in:
lib/structural/model/type_casts.rb

Defined Under Namespace

Classes: Date, Float, Identity, Integer, Money, Time

Class Method Summary collapse

Class Method Details

.cast(type, value) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/structural/model/type_casts.rb', line 5

def self.cast(type, value)
  if value.is_a?(type)
    value
  else
    casts.fetch(type, Identity).cast(value)
  end
end

.register(cast) ⇒ Object



13
14
15
# File 'lib/structural/model/type_casts.rb', line 13

def self.register(cast)
  casts[cast.type] = cast
end