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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b46d807aa97c2e089222447115d7862105246f37f850e65f824f8599af5d714d
4
- data.tar.gz: b2f82f834eb10ead8e14e9b63083093b94a27bdec7a157a7102ee6c01eb15e6a
3
+ metadata.gz: 70ce82947444306a38c71f41034dbc93a842d06125f66d2288ab212b663af42c
4
+ data.tar.gz: 69a1dc6eb190e4d1dca977df29cf3d6c3fe8b2c87334d8a919e1f7022f57bdb2
5
5
  SHA512:
6
- metadata.gz: fb86d0f70a24db611837a597b3f8846a545f9c16d0df2099d6baab0235cc27ff0730b97f55b138b1d946715e3a9a671b6af23544ba59851d6f10b1cde428d9e5
7
- data.tar.gz: 4b4c5ce9982c8faaf53a6eab5117b8250d17fc3e11ffb34e24e3765ad931b5ad1fbd4031633a132c23c7c4d489131ff5364af22a0d695acad02e349b23414d25
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
@@ -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
- # break subdivisions if address.send(field).blank? || address_format.hidden_fields.include?(field)
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Addressing
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addressing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin van der Vleuten