Class: AtlasEngine::AddressImporter::Validation::BaseValidator

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
app/models/atlas_engine/address_importer/validation/base_validator.rb

Direct Known Subclasses

DefaultValidator

Constant Summary collapse

Errors =
T.type_alias { T::Hash[Symbol, T.untyped] }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(country_code:, field_validations:, additional_field_validations: {}) ⇒ BaseValidator

Returns a new instance of BaseValidator.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/atlas_engine/address_importer/validation/base_validator.rb', line 21

def initialize(country_code:, field_validations:, additional_field_validations: {})
  @allow_partial_zip = T.let(CountryProfile.partial_zip_allowed_countries.include?(country_code), T::Boolean)
  @field_validations = field_validations
  @additional_field_validations = additional_field_validations.transform_values do |validator_classes|
    validator_classes.map do |validator_class|
      if validator_class.is_a?(Class)
        validator_class
      else
        validator_class.to_s.constantize
      end
    end
  end

  @caches = {}
  merged_field_validations.map do |field, _validator_class|
    @caches[field] = Set.new
  end

  @errors = T.let(Hash.new([]), Errors)
end

Instance Attribute Details

#additional_field_validationsObject (readonly)

Returns the value of attribute additional_field_validations.



12
13
14
# File 'app/models/atlas_engine/address_importer/validation/base_validator.rb', line 12

def additional_field_validations
  @additional_field_validations
end

#allow_partial_zipObject (readonly)

Returns the value of attribute allow_partial_zip.



12
13
14
# File 'app/models/atlas_engine/address_importer/validation/base_validator.rb', line 12

def allow_partial_zip
  @allow_partial_zip
end

#field_validationsObject (readonly)

Returns the value of attribute field_validations.



12
13
14
# File 'app/models/atlas_engine/address_importer/validation/base_validator.rb', line 12

def field_validations
  @field_validations
end

Instance Method Details

#validation_errors(address:) ⇒ Object



43
44
45
46
# File 'app/models/atlas_engine/address_importer/validation/base_validator.rb', line 43

def validation_errors(address:)
  validate(address: address)
  @errors
end