Class: AtlasEngine::Services::Validation

Inherits:
Object
  • Object
show all
Extended by:
ServiceHelper, T::Sig
Defined in:
app/models/atlas_engine/services/validation.rb

Constant Summary collapse

VALIDATE_ADDRESS =
"validate_address"

Class Method Summary collapse

Methods included from ServiceHelper

handle_metrics

Class Method Details

.validate_address(request) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/atlas_engine/services/validation.rb', line 16

def validate_address(request)
  country_code = request.address.country_code
  handle_metrics(Validation::VALIDATE_ADDRESS, country_code, false) do
    matching_strategy = if validation_enabled?(request.address)
      serialize_strategy(request.matching_strategy, request.address)
    else
      AddressValidation::MatchingStrategies::Local
    end

    message_format = AddressValidation::MessageFormat.try_deserialize(request.message_format) ||
      AddressValidation::MessageFormat::Instructional

    validator = AddressValidation::Validator.new(
      address: request.address,
      locale: request.locale,
      matching_strategy: matching_strategy,
      context: request.address.context.to_h,
      message_format: message_format,
    )
    result = validator.run

    AddressValidation::StatsdEmitter.new(address: request.address, result: result).run
    AddressValidation::LogEmitter.new(address: request.address, result: result).run

    if Rails.configuration.x.captured_concerns.enabled
      AddressValidation::ConcernProducer.add(result, request.address.context.to_h)
    end

    result
  end
end