effective_addresses 1.9.1 → 1.9.5

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: 2aa7ce3d77614bfd059db69cef7d6a5b7d5d43d5fc77a34b8994130c32e7f520
4
- data.tar.gz: 9f57e1ca5e3311d7782938154b8636d3e4f34c38cf7d4b9599efa2c3e35a7294
3
+ metadata.gz: ba2cb481ec7f7168ac0c9ee64c1aba99e55c67b8535a9f55391f554bb059662f
4
+ data.tar.gz: 8210fec82cbfceca33e406e3e093f0e77a98dcf68cd2bb386e75fd3a41796c03
5
5
  SHA512:
6
- metadata.gz: 866ac98ef614cfcee03b0489dccd1fcde01a5d1c1f3ee62325dec9424f071ee8126ee9e883718d9252f33badec6c341ad35ad0a4b5b80a02a557abc7776f5aa8
7
- data.tar.gz: '039fd9d17fdfdf3418aed12003f2792dbf292102058c5a6b7d1409731f759f08a526419c7e7e7492a057ff4347d7d5a8636720cb186e6e94dbbbca4c162bef40'
6
+ metadata.gz: 10354668f36119531aeb01e5a281a7d7f6c8932923b87a162686ff383a3b3af7bfaec819e43e10e5b727ba656325733e172e2005777c140995adbef32993f8e3
7
+ data.tar.gz: f0edbe4d32a1a377a80c8c4a3d02bcc1694094038a07b854c0af5eabf46134cb2ab9d7eff5729a4c2a8bf17fc78186f2b414a413e10efb6dbb00a477734cddf6
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2018 Code and Effect Inc.
1
+ Copyright 2021 Code and Effect Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,6 +1,4 @@
1
1
  module EffectiveAddressesHelper
2
- @@use_geocoder = defined?(Geocoder)
3
-
4
2
  def effective_address_fields(form, method = 'billing', options = {})
5
3
  method = (method.to_s.include?('_address') ? method.to_s : "#{method}_address")
6
4
 
@@ -28,7 +26,7 @@ module EffectiveAddressesHelper
28
26
  if EffectiveAddresses.pre_selected_country.present?
29
27
  address.country = EffectiveAddresses.pre_selected_country
30
28
  address.state = EffectiveAddresses.pre_selected_state if EffectiveAddresses.pre_selected_state.present?
31
- elsif @@use_geocoder && request.location.present?
29
+ elsif defined?(Geocoder) && request.location.present?
32
30
  location = request.location
33
31
  address.country = location.country_code
34
32
  address.state = location.state_code
@@ -37,7 +35,7 @@ module EffectiveAddressesHelper
37
35
  end
38
36
  end
39
37
 
40
- def effective_address_regions_collection(regions = nil)
38
+ def effective_address_regions_collection(regions = nil, resource: nil)
41
39
  if regions.present?
42
40
  countries = regions
43
41
  elsif EffectiveAddresses.country_codes == :all
@@ -61,7 +59,15 @@ module EffectiveAddressesHelper
61
59
  )
62
60
  end
63
61
 
62
+ # Special behaviour if the address has CAN, we treat it as CA
63
+ if regions.blank? && resource.present? && resource.country_code == 'CAN'
64
+ ca = countries.index { |_, code| code == 'CA' }
65
+
66
+ if ca.present?
67
+ countries[ca] = ['Canada', 'CAN']
68
+ end
69
+ end
70
+
64
71
  countries
65
72
  end
66
73
  end
67
-
@@ -8,27 +8,22 @@ module Effective
8
8
 
9
9
  belongs_to :addressable, polymorphic: true, touch: true
10
10
 
11
- if defined?(EffectiveResources)
12
- effective_resource do
13
- category :string
11
+ effective_resource do
12
+ category :string
14
13
 
15
- full_name :string
16
- address1 :string
17
- address2 :string
14
+ full_name :string
15
+ address1 :string
16
+ address2 :string
17
+ address3 :string
18
18
 
19
- if EffectiveAddresses.use_address3
20
- address3 :string
21
- end
22
-
23
- city :string
24
- state_code :string
25
- country_code :string
26
- postal_code :string
19
+ city :string
20
+ state_code :string
21
+ country_code :string
22
+ postal_code :string
27
23
 
28
- shipping_address_same_as_billing permitted: true
24
+ shipping_address_same_as_billing permitted: true
29
25
 
30
- timestamps
31
- end
26
+ timestamps
32
27
  end
33
28
 
34
29
  validates :category, :address1, :city, :country_code, :postal_code, presence: true, if: Proc.new { |address| address.present? }
@@ -26,7 +26,7 @@
26
26
  disabled: same_as_billing,
27
27
  wrapper: wrapper_options
28
28
 
29
- - if fa.object.respond_to?(:address3) && EffectiveAddresses.use_address3
29
+ - if EffectiveAddresses.use_address3
30
30
  = fa.text_field :address3,
31
31
  label: false,
32
32
  required: false,
@@ -41,7 +41,7 @@
41
41
 
42
42
  .row
43
43
  .col-md-4
44
- = fa.select :country_code, effective_address_regions_collection(),
44
+ = fa.select :country_code, effective_address_regions_collection(resource: fa.object),
45
45
  label: 'Country',
46
46
  required: required,
47
47
  disabled: same_as_billing,
@@ -7,9 +7,7 @@ class CreateEffectiveAddresses < ActiveRecord::Migration[4.2]
7
7
  t.string :full_name
8
8
  t.string :address1
9
9
  t.string :address2
10
-
11
- # Uncomment this if you want 3 address fields
12
- # t.string :address3
10
+ t.string :address3
13
11
 
14
12
  t.string :city
15
13
  t.string :state_code
@@ -2,8 +2,8 @@ module EffectiveAddresses
2
2
  class Engine < ::Rails::Engine
3
3
  engine_name 'effective_addresses'
4
4
 
5
- config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
6
- config.autoload_paths += Dir["#{config.root}/app/models/validators"]
5
+ config.autoload_paths += Dir["#{config.root}/lib/validators"]
6
+ config.eager_load_paths += Dir["#{config.root}/lib/validators"]
7
7
 
8
8
  # Include acts_as_addressable concern and allow any ActiveRecord object to call it
9
9
  initializer 'effective_addresses.active_record' do |app|
@@ -19,4 +19,3 @@ module EffectiveAddresses
19
19
 
20
20
  end
21
21
  end
22
-
@@ -1,3 +1,3 @@
1
1
  module EffectiveAddresses
2
- VERSION = '1.9.1'.freeze
2
+ VERSION = '1.9.5'.freeze
3
3
  end
@@ -1,26 +1,31 @@
1
1
  require 'carmen'
2
+ require 'effective_resources'
2
3
  require 'effective_addresses/engine'
3
4
  require 'effective_addresses/version'
4
5
 
5
6
  module EffectiveAddresses
6
7
 
7
- # The following are all valid config keys
8
- mattr_accessor :country_codes
9
- mattr_accessor :country_codes_priority
10
- mattr_accessor :addresses_table_name
11
- mattr_accessor :use_full_name
12
- mattr_accessor :use_address3
13
- mattr_accessor :simple_form_options
14
- mattr_accessor :validate_postal_code_format
15
- mattr_accessor :pre_selected_country
16
- mattr_accessor :pre_selected_state
17
-
18
- def self.setup
19
- yield self
8
+ def self.config_keys
9
+ [
10
+ :addresses_table_name,
11
+ :country_codes,
12
+ :country_codes_priority,
13
+ :use_full_name,
14
+ :use_address3,
15
+ :simple_form_options,
16
+ :validate_postal_code_format,
17
+ :pre_selected_country,
18
+ :pre_selected_state
19
+ ]
20
20
  end
21
21
 
22
+ include EffectiveGem
23
+
22
24
  def self.permitted_params
23
- [:address1, :address2, :address3, :city, :country_code, :state_code, :postal_code, :full_name, :shipping_address_same_as_billing]
25
+ [
26
+ :address1, :address2, :address3, :city, :country_code, :state_code, :postal_code,
27
+ :full_name, :shipping_address_same_as_billing
28
+ ]
24
29
  end
25
30
 
26
31
  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.1
4
+ version: 1.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-17 00:00:00.000000000 Z
11
+ date: 2021-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: effective_resources
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: carmen
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -69,8 +83,6 @@ files:
69
83
  - app/helpers/effective_addresses_helper.rb
70
84
  - app/models/concerns/acts_as_addressable.rb
71
85
  - app/models/effective/address.rb
72
- - app/models/validators/effective_address_full_name_presence_validator.rb
73
- - app/models/validators/effective_address_valid_validator.rb
74
86
  - app/views/effective/addresses/_address.html.haml
75
87
  - app/views/effective/addresses/_form_with.html.haml
76
88
  - app/views/effective/addresses/_formtastic.html.haml
@@ -84,11 +96,13 @@ files:
84
96
  - lib/effective_addresses/engine.rb
85
97
  - lib/effective_addresses/version.rb
86
98
  - lib/generators/effective_addresses/install_generator.rb
99
+ - lib/validators/effective_address_full_name_presence_validator.rb
100
+ - lib/validators/effective_address_valid_validator.rb
87
101
  homepage: https://github.com/code-and-effect/effective_addresses
88
102
  licenses:
89
103
  - MIT
90
104
  metadata: {}
91
- post_install_message:
105
+ post_install_message:
92
106
  rdoc_options: []
93
107
  require_paths:
94
108
  - lib
@@ -103,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
117
  - !ruby/object:Gem::Version
104
118
  version: '0'
105
119
  requirements: []
106
- rubygems_version: 3.0.3
107
- signing_key:
120
+ rubygems_version: 3.1.2
121
+ signing_key:
108
122
  specification_version: 4
109
123
  summary: Extend any ActiveRecord object to have one or more named addresses. Includes
110
124
  a geographic region-aware custom form input backed by Carmen.