Class: ZodRails::Mapping::ValidationMapper

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

Constant Summary collapse

NUMERICALITY_MAP =
{
  greater_than: "gt",
  greater_than_or_equal_to: "gte",
  less_than: "lt",
  less_than_or_equal_to: "lte"
}.freeze
NUMERIC_ZOD_TYPES =
%i[integer float].freeze
STRING_ZOD_TYPES =
%i[string text].freeze

Class Method Summary collapse

Class Method Details

.call(validation, base_type:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/zod_rails/mapping/validation_mapper.rb', line 16

def self.call(validation, base_type:)
  return "" if validation.conditional?

  case validation.kind
  when :presence then map_presence(validation, base_type)
  when :length then map_length(validation, base_type)
  when :numericality then map_numericality(validation, base_type)
  when :format then map_format(validation, base_type)
  when :inclusion then map_inclusion(validation, base_type)
  else ""
  end
end

.call_all(validations, base_type:) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/zod_rails/mapping/validation_mapper.rb', line 29

def self.call_all(validations, base_type:)
  constraints = { min: nil, max: nil, length: nil, others: [] }

  validations.each do |v|
    collect_constraints(v, base_type, constraints)
  end

  build_chain(constraints)
end