Module: Pakyow::Data::Types

Defined in:
lib/pakyow/data/types.rb

Constant Summary collapse

MAPPING =
{
  boolean: Bool.meta(mapping: :boolean),
  date: Date.meta(mapping: :date),
  datetime: DateTime.meta(mapping: :datetime),
  decimal: Coercible::Decimal.meta(mapping: :decimal),
  float: Coercible::Float.meta(mapping: :float),
  integer: Coercible::Integer.meta(mapping: :integer),
  string: Coercible::String.meta(mapping: :string),
  time: Time.meta(mapping: :time)
}.freeze

Class Method Summary collapse

Class Method Details

.type_for(type, additional_types = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/pakyow/data/types.rb', line 21

def self.type_for(type, additional_types = {})
  if type.is_a?(Dry::Types::Type)
    type
  else
    type = type.to_sym
    additional_types.to_h.fetch(type) {
      MAPPING.fetch(type)
    }
  end
rescue KeyError => error
  raise UnknownType.build(error, type: type, context: {
    type: type, types: MAPPING.keys
  })
end