Class: ZodRails::Mapping::TypeMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/zod_rails/mapping/type_mapper.rb

Constant Summary collapse

TYPE_MAP =
{
  string: "z.string()",
  text: "z.string()",
  integer: "z.int()",
  bigint: "z.string()",
  float: "z.number()",
  decimal: "z.string()",
  boolean: "z.boolean()",
  date: "z.iso.date()",
  datetime: "z.iso.datetime()",
  time: "z.string()",
  json: "z.json()",
  jsonb: "z.json()",
  uuid: "z.uuid()",
  binary: "z.string()"
}.freeze

Class Method Summary collapse

Class Method Details

.call(type, nullable: false, input_schema: false, has_default: false) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/zod_rails/mapping/type_mapper.rb', line 23

def self.call(type, nullable: false, input_schema: false, has_default: false)
  base = TYPE_MAP.fetch(type.to_sym) do
    ZodRails.logger.warn("ZodRails: Unknown type '#{type}', falling back to z.unknown()")
    "z.unknown()"
  end

  suffix = determine_suffix(nullable: nullable, input_schema: input_schema, has_default: has_default)
  "#{base}#{suffix}"
end