Module: AttrTypecastable::Types

Defined in:
lib/attr_typecastable/types.rb,
lib/attr_typecastable/types/base.rb,
lib/attr_typecastable/types/date.rb,
lib/attr_typecastable/types/time.rb,
lib/attr_typecastable/types/array.rb,
lib/attr_typecastable/types/float.rb,
lib/attr_typecastable/types/object.rb,
lib/attr_typecastable/types/string.rb,
lib/attr_typecastable/types/symbol.rb,
lib/attr_typecastable/types/boolean.rb,
lib/attr_typecastable/types/integer.rb,
lib/attr_typecastable/types/rational.rb,
lib/attr_typecastable/types/date_time.rb,
lib/attr_typecastable/types/exception.rb,
lib/attr_typecastable/types/big_decimal.rb

Defined Under Namespace

Classes: ArrayBase, ArrayFactory, Base, BigDecimal, Boolean, CastError, Date, DateTime, Float, Integer, Object, Rational, String, Symbol, Time, TypeCasterNotFound

Constant Summary collapse

BASIC_TYPES =
{
  ::Object => AttrTypecastable::Types::Object,
  ::String => AttrTypecastable::Types::String,
  ::Symbol => AttrTypecastable::Types::Symbol,
  ::Integer => AttrTypecastable::Types::Integer,
  ::Time => AttrTypecastable::Types::Time,
  ::Date => AttrTypecastable::Types::Date,
  ::DateTime => AttrTypecastable::Types::DateTime,
  ::Float => AttrTypecastable::Types::Float,
  ::Rational => AttrTypecastable::Types::Rational,
  ::BigDecimal => AttrTypecastable::Types::BigDecimal,
  ::Boolean => AttrTypecastable::Types::Boolean,
}.freeze

Class Method Summary collapse

Class Method Details

.typecaster_for(typecaster, **options) ⇒ Object



40
41
42
43
44
45
# File 'lib/attr_typecastable/types.rb', line 40

def typecaster_for(typecaster, **options)
  const = typecaster.is_a?(::String) ? typecaster.constantize : typecaster
  BASIC_TYPES.fetch(const, const)
rescue NameError
  raise TypeCasterNotFound, "#{typecaster} is undefined"
end