addressing 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/addressing/model.rb +4 -5
- data/lib/addressing/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70ce82947444306a38c71f41034dbc93a842d06125f66d2288ab212b663af42c
|
4
|
+
data.tar.gz: 69a1dc6eb190e4d1dca977df29cf3d6c3fe8b2c87334d8a919e1f7022f57bdb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e8be1a338edaa1a0f39ac942b04786a7c0e88937c148c48ffe851b52b79dfcebb235e6a31800c1ad0c862b26be8ac255469bf3682fdb73e86b11f9d898e18f4
|
7
|
+
data.tar.gz: c4473163b7243a66c8846e77d6f6d267af3c3a33f3b483aa2ef2098d3dd8942885dcb7044e0bc15f2a3a889b79453ea658ad8cf3ea503c54770aa1725ced5315
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
All notable changes to `addressing` will be documented in this file.
|
4
4
|
|
5
|
+
## 0.3.1 (04-04-2022)
|
6
|
+
|
7
|
+
- Break with both subdivisions and parents when subdivision field is empty
|
8
|
+
- Only retrieve field if it exists on model
|
9
|
+
|
5
10
|
## 0.3.0 (04-04-2022)
|
6
11
|
|
7
12
|
- Allow field validation to be overridden
|
data/lib/addressing/model.rb
CHANGED
@@ -13,7 +13,7 @@ module Addressing
|
|
13
13
|
validate :verify_address_format, **options
|
14
14
|
|
15
15
|
define_method :verify_address_format do
|
16
|
-
values = fields.each_with_object({}) { |f, v| v[f] = send(f) }
|
16
|
+
values = fields.each_with_object({}) { |f, v| v[f] = send(f) if self.respond_to?(f) }
|
17
17
|
address = Address.new(**values)
|
18
18
|
|
19
19
|
return unless address.country_code.present?
|
@@ -44,20 +44,19 @@ module Addressing
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# Validate subdivisions.
|
47
|
-
subdivisions = verify_subdivisions(address, address_format)
|
47
|
+
subdivisions = verify_subdivisions(address, address_format, field_overrides)
|
48
48
|
|
49
49
|
# Validate postal code.
|
50
50
|
verify_postal_code(address.postal_code, subdivisions, address_format) if used_fields.include?(AddressField::POSTAL_CODE)
|
51
51
|
end
|
52
52
|
|
53
|
-
define_method :verify_subdivisions do |address, address_format|
|
53
|
+
define_method :verify_subdivisions do |address, address_format, field_overrides|
|
54
54
|
# No predefined subdivisions exist, nothing to validate against.
|
55
55
|
return [] if address_format.subdivision_depth < 1
|
56
56
|
|
57
57
|
subdivisions, _parents = address_format.used_subdivision_fields.each_with_index.inject([[], []]) do |(subdivisions, parents), (field, index)|
|
58
58
|
# The field is empty or validation is disabled.
|
59
|
-
|
60
|
-
break subdivisions if address.send(field).blank?
|
59
|
+
break [subdivisions, parents] if address.send(field).blank? || field_overrides.hidden_fields.include?(field)
|
61
60
|
|
62
61
|
parents << (index > 0 ? address.send(address_format.used_subdivision_fields[index - 1]) : address_format.country_code)
|
63
62
|
subdivision = Subdivision.get(address.send(field), parents)
|
data/lib/addressing/version.rb
CHANGED