Class: AtlasEngine::AddressValidation::Es::Datastore
- Inherits:
-
Object
- Object
- AtlasEngine::AddressValidation::Es::Datastore
show all
- Extended by:
- T::Sig
- Includes:
- DatastoreBase, LogHelper, MetricsHelper
- Defined in:
- app/models/atlas_engine/address_validation/es/datastore.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from LogHelper
#log_error, #log_info, #log_warn
#measure_distribution
Constructor Details
#initialize(address:, locale: nil) ⇒ Datastore
Returns a new instance of Datastore.
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 22
def initialize(address:, locale: nil)
@address = address
@locale = locale
raise ArgumentError, "address has no country_code" if address.country_code.blank?
@country_code = T.must(address.country_code.to_s)
@country_profile = CountryProfile.for(country_code.to_s.upcase, @locale)
if locale.nil? && @country_profile.validation.multi_locale?
raise ArgumentError, "#{country_code} is a multi-locale country and requires a locale"
end
@parsings = ValidationTranscriber::AddressParsings.new(address_input: address, locale: locale)
@query_builder = QueryBuilder.for(address, parsings, locale)
end
|
Instance Attribute Details
#candidates=(value) ⇒ Object
meant for test setup only
19
20
21
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 19
def candidates=(value)
@candidates = value
end
|
#country_profile ⇒ Object
Returns the value of attribute country_profile.
14
15
16
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 14
def country_profile
@country_profile
end
|
#parsings ⇒ Object
Returns the value of attribute parsings.
17
18
19
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 17
def parsings
@parsings
end
|
Instance Method Details
#city_sequence=(sequence) ⇒ Object
52
53
54
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 52
def city_sequence=(sequence)
@city_sequence_future = Concurrent::Promises.fulfilled_future(sequence)
end
|
#fetch_city_sequence ⇒ Object
57
58
59
60
61
62
63
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 57
def fetch_city_sequence
log_future_state_on_join(future: @city_sequence_future, method: "city_sequence")
@city_sequence_future ||= Concurrent::Promises.fulfilled_future(fetch_city_sequence_internal)
@city_sequence_future.value!
end
|
#fetch_city_sequence_async ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 66
def fetch_city_sequence_async
submit_time = Time.current
@city_sequence_future ||= Concurrent::Promises.future do
measure_future_queue_time(enqueue_time: submit_time, method: "city_sequence")
fetch_city_sequence_internal
end
end
|
#fetch_full_address_candidates ⇒ Object
100
101
102
103
104
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 100
def fetch_full_address_candidates
@candidates ||= fetch_addresses_internal.map { |address| Candidate.from(address) }.tap do |candidates|
assign_term_vectors_to_candidates(candidates) if candidates.present?
end
end
|
#fetch_street_sequences ⇒ Object
81
82
83
84
85
86
87
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 81
def fetch_street_sequences
log_future_state_on_join(future: @street_sequences_future, method: "all_street_sequences")
@street_sequences_future ||= Concurrent::Promises.fulfilled_future(fetch_street_sequences_internal)
@street_sequences_future.value!
end
|
#fetch_street_sequences_async ⇒ Object
90
91
92
93
94
95
96
97
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 90
def fetch_street_sequences_async
submit_time = Time.current
@street_sequences_future ||= Concurrent::Promises.future do
measure_future_queue_time(enqueue_time: submit_time, method: "all_street_sequences")
fetch_street_sequences_internal
end
end
|
#repository ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 42
def repository
@repository ||= CountryRepository.new(
country_code: country_code.downcase,
repository_class: AtlasEngine.elasticsearch_repository.constantize,
locale: locale&.downcase,
index_configuration: nil,
)
end
|
#street_sequences=(sequences) ⇒ Object
76
77
78
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 76
def street_sequences=(sequences)
@street_sequences_future = Concurrent::Promises.fulfilled_future(sequences)
end
|
#validation_response ⇒ Object
107
108
109
110
111
|
# File 'app/models/atlas_engine/address_validation/es/datastore.rb', line 107
def validation_response
{
body: fetch_addresses_internal,
}
end
|