Class: Attribeauty::TypeCaster

Inherits:
Object
  • Object
show all
Defined in:
lib/attribeauty/type_caster.rb

Overview

base cast for types

Constant Summary collapse

BASE_TYPES =
{
  float: Types::Float,
  integer: Types::Integer,
  boolean: Types::Boolean,
  time: Types::Time,
  string: Types::String
}.freeze

Class Method Summary collapse

Class Method Details

.run(value, type) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
# File 'lib/attribeauty/type_caster.rb', line 14

def self.run(value, type)
  return nil if value.nil?

  all_types = Attribeauty.configuration.types

  raise ArgumentError, "#{type} not supported" if all_types[type].nil?

  all_types[type].new.cast(value)
end