effective_addresses 1.8.5 → 1.9.3

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
- SHA1:
3
- metadata.gz: 10e0a18e1057bb62aa50278891d207d8cfb1420a
4
- data.tar.gz: 09d6a1fa25e100cc1e1690d53015799d0447d874
2
+ SHA256:
3
+ metadata.gz: e41141e340c412a2e083dfb79792a86f102484fe61734eebf85963ba17c287c8
4
+ data.tar.gz: f0f60629f50f7f20e3e8ba6976e6ba9554b18ed6bb38870a4653ab1ad33b9c17
5
5
  SHA512:
6
- metadata.gz: 52d258748596da058b01e2a092f810ade1451171bb56035dec4b39292530aa603a88574c5ab60ae27d7bbf5dce030c872d6efae6b14035e4dbd2d3b10e322b10
7
- data.tar.gz: 6af33db771036fd87c82e991917d8b96cac6d7ab461b715587752d8dcf6d7b9d776b9de058093bc84b1cbd1e4d3e12da5fb7c66506720b1a5429ad45e835df3a
6
+ metadata.gz: 934bf8000a28eb370e5f444d6f70610ea7b63f5c0d71c0e1da9f1ed0d83265b697b424489b732d2469e3a23edde57c603d11b2daf2aec9a4688635239e45ee4d
7
+ data.tar.gz: 170e98c482c1d99e3907864773762f487f0b61b0e5fc8399ffcac6c11f4d03655b547450d0c7a8ae856b97a7b13469bbe83f7a602ad8304b9ae32397f9f82179
@@ -37,7 +37,7 @@ module EffectiveAddressesHelper
37
37
  end
38
38
  end
39
39
 
40
- def effective_address_regions_collection(regions = nil)
40
+ def effective_address_regions_collection(regions = nil, resource: nil)
41
41
  if regions.present?
42
42
  countries = regions
43
43
  elsif EffectiveAddresses.country_codes == :all
@@ -61,10 +61,15 @@ module EffectiveAddressesHelper
61
61
  )
62
62
  end
63
63
 
64
+ # Special behaviour if the address has CAN, we treat it as CA
65
+ if regions.blank? && resource.present? && resource.country_code == 'CAN'
66
+ ca = countries.index { |_, code| code == 'CA' }
67
+
68
+ if ca.present?
69
+ countries[ca] = ['Canada', 'CAN']
70
+ end
71
+ end
72
+
64
73
  countries
65
74
  end
66
- alias_method :effective_address_countries_collection, :effective_address_regions_collection
67
- alias_method :region_options_for_simple_form_select, :effective_address_regions_collection
68
-
69
75
  end
70
-
@@ -3,7 +3,7 @@
3
3
  module ActsAsAddressable
4
4
  extend ActiveSupport::Concern
5
5
 
6
- module ActiveRecord
6
+ module Base
7
7
  def acts_as_addressable(*options)
8
8
  @acts_as_addressable_opts = options || []
9
9
  include ::ActsAsAddressable
@@ -91,6 +91,7 @@ module ActsAsAddressable
91
91
  return effective_address(category) if address == effective_address(category)
92
92
 
93
93
  (self.addresses.build).tap do |existing|
94
+ existing.addressable = self
94
95
  existing.category = category.to_s
95
96
  existing.full_name = address.full_name
96
97
  existing.address1 = address.address1
@@ -117,6 +118,7 @@ module ActsAsAddressable
117
118
  return effective_address(category) if address == effective_address(category)
118
119
 
119
120
  (effective_address(category) || self.addresses.build).tap do |existing|
121
+ existing.addressable = self
120
122
  existing.category = category.to_s
121
123
  existing.full_name = address.full_name
122
124
  existing.address1 = address.address1
@@ -41,7 +41,7 @@
41
41
 
42
42
  .row
43
43
  .col-md-4
44
- = fa.select :country_code, effective_address_countries_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,
@@ -29,7 +29,7 @@
29
29
  :as => (defined?(EffectiveFormInputs) ? :effective_select : :select),
30
30
  :label => 'Country',
31
31
  :prompt => 'Country...',
32
- :collection => region_options_for_select(EffectiveAddresses.country_codes == :all ? Carmen::Country.all : Carmen::Country.all.select{ |c| EffectiveAddresses.country_codes.include?(c.code) rescue true}, fa.object.country_code, :priority => EffectiveAddresses.country_codes_priority),
32
+ :collection => options_for_select(effective_address_regions_collection()),
33
33
  :input_html => { 'data-effective-address-country' => uuid },
34
34
  :input_js => { placeholder: 'Please choose' }
35
35
 
@@ -38,7 +38,7 @@
38
38
  = fa.input :state_code,
39
39
  :as => (defined?(EffectiveFormInputs) ? :effective_select : :select),
40
40
  :label => 'Province / State',
41
- :collection => region_options_for_select(Carmen::Country.coded(fa.object.country_code).subregions, fa.object.state_code),
41
+ :collection => options_for_select(effective_address_regions_collection(Carmen::Country.coded(fa.object.country_code).subregions)),
42
42
  :prompt => 'please select a country',
43
43
  :input_html => { 'data-effective-address-state' => uuid },
44
44
  :input_js => { :placeholder => 'Please choose' }
@@ -41,7 +41,7 @@
41
41
  = fa.input :country_code,
42
42
  as: (defined?(EffectiveFormInputs) ? :effective_select : :select),
43
43
  required: required,
44
- collection: effective_address_countries_collection(),
44
+ collection: effective_address_regions_collection(),
45
45
  input_html: {'data-effective-address-country' => uuid},
46
46
  disabled: shipping_address_same_as_billing,
47
47
  wrapper_html: { style: ('display: none;' if shipping_address_same_as_billing) }
@@ -1 +1 @@
1
- = region_options_for_select(@subregions)
1
+ = options_for_select(effective_address_regions_collection(@subregions))
@@ -1,5 +1,4 @@
1
1
  require 'carmen'
2
- require 'carmen-rails'
3
2
  require 'effective_addresses/engine'
4
3
  require 'effective_addresses/version'
5
4
 
@@ -2,13 +2,13 @@ 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|
10
10
  ActiveSupport.on_load :active_record do
11
- ActiveRecord::Base.extend(ActsAsAddressable::ActiveRecord)
11
+ ActiveRecord::Base.extend(ActsAsAddressable::Base)
12
12
  end
13
13
  end
14
14
 
@@ -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.8.5'.freeze
2
+ VERSION = '1.9.3'.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.8.5
4
+ version: 1.9.3
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: 2018-10-05 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: carmen-rails
28
+ name: carmen
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -69,8 +69,6 @@ files:
69
69
  - app/helpers/effective_addresses_helper.rb
70
70
  - app/models/concerns/acts_as_addressable.rb
71
71
  - 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
72
  - app/views/effective/addresses/_address.html.haml
75
73
  - app/views/effective/addresses/_form_with.html.haml
76
74
  - app/views/effective/addresses/_formtastic.html.haml
@@ -84,11 +82,13 @@ files:
84
82
  - lib/effective_addresses/engine.rb
85
83
  - lib/effective_addresses/version.rb
86
84
  - lib/generators/effective_addresses/install_generator.rb
85
+ - lib/validators/effective_address_full_name_presence_validator.rb
86
+ - lib/validators/effective_address_valid_validator.rb
87
87
  homepage: https://github.com/code-and-effect/effective_addresses
88
88
  licenses:
89
89
  - MIT
90
90
  metadata: {}
91
- post_install_message:
91
+ post_install_message:
92
92
  rdoc_options: []
93
93
  require_paths:
94
94
  - lib
@@ -103,9 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.4.5.1
108
- signing_key:
106
+ rubygems_version: 3.1.2
107
+ signing_key:
109
108
  specification_version: 4
110
109
  summary: Extend any ActiveRecord object to have one or more named addresses. Includes
111
110
  a geographic region-aware custom form input backed by Carmen.