effective_addresses 1.9.2 → 1.9.6

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: f68f7e9190672bf40b176596387019c6e4ff3ce76f299950469dba367eca0d77
4
- data.tar.gz: 180012dead028e83f163659605bc5f55dc9c345f3fccce1e201cf140f83c21a4
3
+ metadata.gz: 46461b09d7aa12fd73789e0d29640bac574d2b7295bb68ce8568cc64c0b52f30
4
+ data.tar.gz: 00b4f0c30fedc4ddaa7cf8a700a221768ad077322846494093850a575bf45d11
5
5
  SHA512:
6
- metadata.gz: b879876863da03b54413dd98e9bce145e77e166b99822d8315c1f2d9620c150fb9999a1303aaeeb75e256c28aae9bc64c47391a1713deca10d53b6d462d78196
7
- data.tar.gz: d6855b8a7b2b6171c1a88d973abd73347152ab5ce90884ded6409136f767aaf07b087126045bbc4a743f1605e2a9fe9cf1597d567f60d6e5227d4aa18de7c63e
6
+ metadata.gz: 1fb5fb6857f90e57e50fe17e4f28aa27732fb932dd57a9287041a8afb25b63ada63c6c8d870871026c4bbb51067b8ea6de7b33b68e6634a6c90141706358adc1
7
+ data.tar.gz: 61324d4eecfa40edc2c3b5cfc2957d59d96463e5bb3f55b2ad7d339a67c7cde1f849f4882f4167910311a6fc6e9788470015ce2acaa8b6edfaa96fa6fc080814
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
data/README.md CHANGED
@@ -89,7 +89,7 @@ or
89
89
 
90
90
  ```ruby
91
91
  class User
92
- acts_as_addressable :billing => {:presence => true, :use_full_name => false}
92
+ acts_as_addressable :billing => {:presence => true}
93
93
  end
94
94
  ```
95
95
 
@@ -110,11 +110,7 @@ This means when a User is created, it will not be valid unless a billing_address
110
110
 
111
111
  Sometimes you want to collect a `full_name` field with your addresses, such as in the case of a mailing address; other times, it's an unnecessary field.
112
112
 
113
- When you specify the config option `config.use_full_name = true` all `acts_as_addressable` defined addresses will use `use_full_name => true` by default.
114
-
115
- This can be overridden on a per-address basis when declared in the model.
116
-
117
- When `use_full_name == true`, any calls to `effective_address_fields` form helper will display the full_name input, and the model will `validate_presence_of :full_name`.
113
+ When you specify the config option `config.use_full_name = true` all, any calls to `effective_address_fields` form helper will display the full_name input, and the model will `validate_presence_of :full_name`.
118
114
 
119
115
 
120
116
  ### Address Validations
@@ -1,16 +1,13 @@
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
 
7
5
  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
- use_full_name = form.object._validators[method.to_sym].any? { |v| v.kind_of?(EffectiveAddressFullNamePresenceValidator) }
9
6
 
10
7
  address = form.object.send(method) || form.object.addresses.build(category: method.to_s.gsub('_address', ''))
11
8
  effective_address_pre_select(address) if address.new_record?
12
9
 
13
- opts = { required: required, use_full_name: use_full_name, field_order: [:full_name, :address1, :address2, :city, :country_code, :state_code, :postal_code] }.merge(options).merge({:f => form, :address => address, :method => method})
10
+ 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})
14
11
 
15
12
  case form.class.name
16
13
  when 'Effective::FormBuilder'
@@ -28,7 +25,7 @@ module EffectiveAddressesHelper
28
25
  if EffectiveAddresses.pre_selected_country.present?
29
26
  address.country = EffectiveAddresses.pre_selected_country
30
27
  address.state = EffectiveAddresses.pre_selected_state if EffectiveAddresses.pre_selected_state.present?
31
- elsif @@use_geocoder && request.location.present?
28
+ elsif defined?(Geocoder) && request.location.present?
32
29
  location = request.location
33
30
  address.country = location.country_code
34
31
  address.state = location.state_code
@@ -37,7 +34,7 @@ module EffectiveAddressesHelper
37
34
  end
38
35
  end
39
36
 
40
- def effective_address_regions_collection(regions = nil)
37
+ def effective_address_regions_collection(regions = nil, resource: nil)
41
38
  if regions.present?
42
39
  countries = regions
43
40
  elsif EffectiveAddresses.country_codes == :all
@@ -61,7 +58,15 @@ module EffectiveAddressesHelper
61
58
  )
62
59
  end
63
60
 
61
+ # Special behaviour if the address has CAN, we treat it as CA
62
+ if regions.blank? && resource.present? && resource.country_code == 'CAN'
63
+ ca = countries.index { |_, code| code == 'CA' }
64
+
65
+ if ca.present?
66
+ countries[ca] = ['Canada', 'CAN']
67
+ end
68
+ end
69
+
64
70
  countries
65
71
  end
66
72
  end
67
-
@@ -23,7 +23,7 @@ module ActsAsAddressable
23
23
  end
24
24
 
25
25
  # Categories can be either:
26
- # {'billing'=>{:singular=>true, :use_full_name=>false}, 'shipping'=>{:singular=>true, :use_full_name=>false}}
26
+ # {'billing'=>{:singular=>true}, 'shipping'=>{:singular=>true}}
27
27
  # or
28
28
  # {'billing' => true, 'shipping' => true}
29
29
  # or
@@ -46,11 +46,13 @@ module ActsAsAddressable
46
46
 
47
47
  case options
48
48
  when Hash
49
- validates "#{category}_address", presence: options.fetch(:presence, false)
50
- validates "#{category}_address", effective_address_full_name_presence: options.fetch(:use_full_name, EffectiveAddresses.use_full_name)
51
- when TrueClass, FalseClass
52
- validates "#{category}_address", presence: (options == true)
53
- validates "#{category}_address", effective_address_full_name_presence: EffectiveAddresses.use_full_name
49
+ validates("#{category}_address", presence: true) if options[:presence]
50
+ validates("#{category}_address", effective_address_full_name_presence: true) if options[:use_full_name]
51
+ when TrueClass
52
+ validates "#{category}_address", presence: true
53
+ validates "#{category}_address", effective_address_full_name_presence: true, if: -> { EffectiveAddresses.use_full_name }
54
+ when FalseClass
55
+ # Nothing to do
54
56
  else
55
57
  raise 'Unexpected options. Expected a Hash or Boolean'
56
58
  end
@@ -133,4 +135,3 @@ module ActsAsAddressable
133
135
  end
134
136
 
135
137
  end
136
-
@@ -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? }
@@ -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 use_full_name || fa.object.errors.include?(:full_name)
11
+ - if 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,
@@ -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,
@@ -9,7 +9,7 @@
9
9
 
10
10
  - case field
11
11
  - when :full_name
12
- - if use_full_name || fa.object.errors.include?(:full_name)
12
+ - if 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 use_full_name || fa.object.errors.include?(:full_name)
13
+ - if 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,
@@ -81,4 +81,3 @@
81
81
  label: 'Shipping address is same as billing address',
82
82
  required: false,
83
83
  input_html: { checked: shipping_address_same_as_billing }
84
-
@@ -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
@@ -1,3 +1,3 @@
1
1
  module EffectiveAddresses
2
- VERSION = '1.9.2'.freeze
2
+ VERSION = '1.9.6'.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.2
4
+ version: 1.9.6
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: 2020-08-13 00:00:00.000000000 Z
11
+ date: 2021-10-27 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