effective_addresses 1.8.6 → 1.9.4

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: 16c334b39d46959ee4075c80627675a6a65ef8cc7810bfbcd887fc3a6746803a
4
- data.tar.gz: 1dc9024d1f07d0b6d9b0ab998d9433cc5332c554026c47a5bc70c858f4532f4b
3
+ metadata.gz: 903de54494687e66176870441f7dbf08122086a9d1de3dae3a38da0cbd2cca99
4
+ data.tar.gz: 8535f034cd7392a7f9ee711386248618f2b8d647784e30dfc4fc726220ec55c5
5
5
  SHA512:
6
- metadata.gz: 90da29758f3cde3766a4d0000b04e586ba4796e647cfabe3cfd6429dadf21ff87fd05a4a8cc907da22951865dd7e3c45651cbae7661d5ea3677ef5fd849b0ae0
7
- data.tar.gz: 7b36d586e4e89ac1af6a485a4389e347b4f6df9e72a2131541f866d39bb7af24f5343b33f67b6de5cde899b35282fedfa1e738b2a20dbfb5ce1dd4abdaa66b16
6
+ metadata.gz: 0601a1e879b7cdce8604dd836bd4d80bbca09c1606ff68523ef591b07925ad9b5aba9c679a060a82b7cc5b3e16fa8f2bd0a9a4301ca4e1ab399d9c610ee81b94
7
+ data.tar.gz: 0fc12952f62102c4f792a4c25f380daec74a862a5a6a1fab39edd1a2546d11aa44442ea41c60318b64d3773e4a1adb965e767f5b18ed6c50c079f0b8e29f0b45
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,10 +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
- 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
73
  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
@@ -8,27 +8,25 @@ 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
18
17
 
19
- if EffectiveAddresses.use_address3
20
- address3 :string
21
- end
18
+ if EffectiveAddresses.use_address3
19
+ address3 :string
20
+ end
22
21
 
23
- city :string
24
- state_code :string
25
- country_code :string
26
- postal_code :string
22
+ city :string
23
+ state_code :string
24
+ country_code :string
25
+ postal_code :string
27
26
 
28
- shipping_address_same_as_billing permitted: true
27
+ shipping_address_same_as_billing permitted: true
29
28
 
30
- timestamps
31
- end
29
+ timestamps
32
30
  end
33
31
 
34
32
  validates :category, :address1, :city, :country_code, :postal_code, presence: true, if: Proc.new { |address| address.present? }
@@ -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,27 +1,31 @@
1
1
  require 'carmen'
2
- require 'carmen-rails'
2
+ require 'effective_resources'
3
3
  require 'effective_addresses/engine'
4
4
  require 'effective_addresses/version'
5
5
 
6
6
  module EffectiveAddresses
7
7
 
8
- # The following are all valid config keys
9
- mattr_accessor :country_codes
10
- mattr_accessor :country_codes_priority
11
- mattr_accessor :addresses_table_name
12
- mattr_accessor :use_full_name
13
- mattr_accessor :use_address3
14
- mattr_accessor :simple_form_options
15
- mattr_accessor :validate_postal_code_format
16
- mattr_accessor :pre_selected_country
17
- mattr_accessor :pre_selected_state
18
-
19
- def self.setup
20
- 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
+ ]
21
20
  end
22
21
 
22
+ include EffectiveGem
23
+
23
24
  def self.permitted_params
24
- [: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
+ ]
25
29
  end
26
30
 
27
31
  end
@@ -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.6'.freeze
2
+ VERSION = '1.9.4'.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.6
4
+ version: 1.9.4
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: 2019-12-31 00:00:00.000000000 Z
11
+ date: 2021-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,7 +25,21 @@ 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: 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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: carmen
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -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.