effective_addresses 1.9.9 → 1.10.0

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: fd974c66e5bcdc5eaa644505a3cdc1dcad2aaa54de34597bb81d1bdef2c403f9
4
- data.tar.gz: 215d02c276840271457e6322d979abb53ad27c996af3e748466d16fbed3c8179
3
+ metadata.gz: 2eb87bcd5e2d0b539e5dc27eaaffda71ac6bae2c95742fbdd75269160ada6a32
4
+ data.tar.gz: c86451bdef0b5dc667ee0221ec10600bfcd5fd846ace0fbcfb3c5c6d2e4aa5b2
5
5
  SHA512:
6
- metadata.gz: d365f1068f255e29cf975e5e88877519eb600c1238a5d53e85bd8a0a0411721f3e80d2c5d4af7770dd9dab34110b732d0826b7ca40d2be627ce37c35921c4f42
7
- data.tar.gz: 2ccb92180c02b9ddd9251d8262d476845079c92ced8e475f2247015037009760925958d68fab710b81f5c8cd2f2fef912d3e2c2c8457e79bcc5400beb297a1ba
6
+ metadata.gz: d6697c436d4d56e8e4b4454c4c3027247468fa59d9cf49572360b7a56d9fec28311c671c6af9f5d70196bac13a43f7b5e9f07c3cef68fbbb99be0c709ddb0faf
7
+ data.tar.gz: 47b035caafa985f7eec3b448329ac4b1ddbab54b9699ff9072f13bfc8abe4b333e59a1c3ff4b80794734012d9f68a26aca5df97bb81a1aadd99b1d99da67465e
@@ -7,6 +7,7 @@ module EffectiveAddressesHelper
7
7
  required = (form.object._validators[method.to_sym].any? { |v| v.kind_of?(ActiveRecord::Validations::PresenceValidator) && (v.options[:if].blank? || (v.options[:if].respond_to?(:call) ? f.object.instance_exec(&v.options[:if]) : v.options[:if])) } rescue true)
8
8
 
9
9
  address = form.object.send(method) || form.object.addresses.build(category: method.to_s.gsub('_address', ''))
10
+
10
11
  effective_address_pre_select(address) if address.new_record?
11
12
 
12
13
  opts = { required: required, field_order: [:full_name, :address1, :address2, :city, :country_code, :state_code, :postal_code] }.merge(options).merge({:f => form, :address => address, :method => method})
@@ -24,16 +25,23 @@ module EffectiveAddressesHelper
24
25
  end
25
26
 
26
27
  def effective_address_pre_select(address)
27
- if EffectiveAddresses.pre_selected_country.present?
28
- address.country ||= EffectiveAddresses.pre_selected_country
29
- address.state ||= EffectiveAddresses.pre_selected_state if EffectiveAddresses.pre_selected_state.present?
30
- elsif defined?(Geocoder) && request.location.present?
28
+ if address.country.blank? && EffectiveAddresses.pre_selected_country.present?
29
+ address.country = EffectiveAddresses.pre_selected_country
30
+ end
31
+
32
+ if address.state.blank? && EffectiveAddresses.pre_selected_state.present?
33
+ address.state = EffectiveAddresses.pre_selected_state
34
+ end
35
+
36
+ if defined?(Geocoder) && request.try(:location).present?
31
37
  location = request.location
32
38
  address.country = location.country_code
33
39
  address.state = location.state_code
34
40
  address.postal_code = location.postal_code
35
41
  address.city = location.city
36
42
  end
43
+
44
+ address
37
45
  end
38
46
 
39
47
  def effective_address_regions_collection(regions = nil, resource: nil)
@@ -6,7 +6,7 @@ module Effective
6
6
  attr_accessor :shipping_address_same_as_billing
7
7
 
8
8
  POSTAL_CODE_CA = /\A[A-Z]{1}\d{1}[A-Z]{1}\ \d{1}[A-Z]{1}\d{1}\z/ # Matches 'T5Z 2B1'
9
- POSTAL_CODE_US = /\A\d{5}\z/ # Matches 5 digits
9
+ POSTAL_CODE_US = /\A\d{5}(-\d{4})?\z/ # matches 5 digits plus optional hyphen and 4 digits
10
10
 
11
11
  belongs_to :addressable, polymorphic: true, touch: true
12
12
 
@@ -93,6 +93,7 @@ module Effective
93
93
  code = code.insert(3, ' ') if code.length == 6
94
94
  elsif country_code == 'US'
95
95
  code = code.gsub(/[^0-9]/, '')
96
+ code = code.insert(5, '-') if code.length == 9
96
97
  end
97
98
  end
98
99
 
@@ -13,7 +13,7 @@
13
13
  = address.address2
14
14
  %br
15
15
 
16
- - if address.respond_to?(:address3) && address.address3.present?
16
+ - if address.try(:address3).present?
17
17
  = address.address3
18
18
  %br
19
19
 
@@ -8,7 +8,7 @@
8
8
  - if ((f.object.errors.include?(method) && !f.object.errors.include?(:addresses)) rescue false)
9
9
  = f.errors method
10
10
 
11
- - if EffectiveAddresses.use_full_name || fa.object.errors.include?(:full_name)
11
+ - if local_assigns[:use_full_name] || EffectiveAddresses.use_full_name || fa.object.errors.include?(:full_name)
12
12
  = fa.text_field :full_name,
13
13
  required: required,
14
14
  disabled: same_as_billing,
@@ -9,7 +9,7 @@
9
9
 
10
10
  - case field
11
11
  - when :full_name
12
- - if EffectiveAddresses.use_full_name || fa.object.errors.include?(:full_name)
12
+ - if local_assigns[:use_full_name] || EffectiveAddresses.use_full_name || fa.object.errors.include?(:full_name)
13
13
  = fa.input :full_name, :required => true, :label => 'Full name', :placeholder => 'Full name'
14
14
 
15
15
  - when :address1
@@ -10,7 +10,7 @@
10
10
 
11
11
  - case field
12
12
  - when :full_name
13
- - if EffectiveAddresses.use_full_name || fa.object.errors.include?(:full_name)
13
+ - if local_assigns[:use_full_name] || EffectiveAddresses.use_full_name || fa.object.errors.include?(:full_name)
14
14
  = fa.input :full_name,
15
15
  required: required,
16
16
  disabled: shipping_address_same_as_billing,
@@ -1,3 +1,3 @@
1
1
  module EffectiveAddresses
2
- VERSION = '1.9.9'.freeze
2
+ VERSION = '1.10.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_addresses
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.9
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-11 00:00:00.000000000 Z
11
+ date: 2022-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails