effective_addresses 1.9.4 → 1.9.8

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: 903de54494687e66176870441f7dbf08122086a9d1de3dae3a38da0cbd2cca99
4
- data.tar.gz: 8535f034cd7392a7f9ee711386248618f2b8d647784e30dfc4fc726220ec55c5
3
+ metadata.gz: 745f86571f2a0f52bf54edf6045a56c5ac5537f1b414344ab55a778b402b8f0b
4
+ data.tar.gz: ba0656435d9378d950fa2165c7c936bc8a1542827889b60a3cadff148f780ec4
5
5
  SHA512:
6
- metadata.gz: 0601a1e879b7cdce8604dd836bd4d80bbca09c1606ff68523ef591b07925ad9b5aba9c679a060a82b7cc5b3e16fa8f2bd0a9a4301ca4e1ab399d9c610ee81b94
7
- data.tar.gz: 0fc12952f62102c4f792a4c25f380daec74a862a5a6a1fab39edd1a2546d11aa44442ea41c60318b64d3773e4a1adb965e767f5b18ed6c50c079f0b8e29f0b45
6
+ metadata.gz: '059f454408860bea37b7627c1269ee37ca7b9835fb04d0bed34e9cb0b20a4128a3dadbd2ab2ff9e7462e632da6cb9512ad96f034122375008f86b04a9e276cf4'
7
+ data.tar.gz: 7d157adab8db96dffefdb8dbe18037cd37fc1f1858f86afe60c6985d8984161ed1f6b40d8a6297e83cfdc4c5099dd055620c1e9267ee8233a569ca31461fd526
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,14 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EffectiveAddressesHelper
2
4
  def effective_address_fields(form, method = 'billing', options = {})
3
5
  method = (method.to_s.include?('_address') ? method.to_s : "#{method}_address")
4
6
 
5
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)
6
- use_full_name = form.object._validators[method.to_sym].any? { |v| v.kind_of?(EffectiveAddressFullNamePresenceValidator) }
7
8
 
8
9
  address = form.object.send(method) || form.object.addresses.build(category: method.to_s.gsub('_address', ''))
9
10
  effective_address_pre_select(address) if address.new_record?
10
11
 
11
- 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})
12
+ 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})
12
13
 
13
14
  case form.class.name
14
15
  when 'Effective::FormBuilder'
@@ -24,8 +25,8 @@ module EffectiveAddressesHelper
24
25
 
25
26
  def effective_address_pre_select(address)
26
27
  if EffectiveAddresses.pre_selected_country.present?
27
- address.country = EffectiveAddresses.pre_selected_country
28
- address.state = EffectiveAddresses.pre_selected_state if EffectiveAddresses.pre_selected_state.present?
28
+ address.country ||= EffectiveAddresses.pre_selected_country
29
+ address.state ||= EffectiveAddresses.pre_selected_state if EffectiveAddresses.pre_selected_state.present?
29
30
  elsif defined?(Geocoder) && request.location.present?
30
31
  location = request.location
31
32
  address.country = location.country_code
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # ActsAsAddressable
2
4
 
3
5
  module ActsAsAddressable
@@ -23,7 +25,7 @@ module ActsAsAddressable
23
25
  end
24
26
 
25
27
  # Categories can be either:
26
- # {'billing'=>{:singular=>true, :use_full_name=>false}, 'shipping'=>{:singular=>true, :use_full_name=>false}}
28
+ # {'billing'=>{:singular=>true}, 'shipping'=>{:singular=>true}}
27
29
  # or
28
30
  # {'billing' => true, 'shipping' => true}
29
31
  # or
@@ -46,11 +48,13 @@ module ActsAsAddressable
46
48
 
47
49
  case options
48
50
  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
51
+ validates("#{category}_address", presence: true) if options[:presence]
52
+ validates("#{category}_address", effective_address_full_name_presence: true) if options[:use_full_name]
53
+ when TrueClass
54
+ validates "#{category}_address", presence: true
55
+ validates "#{category}_address", effective_address_full_name_presence: true, if: -> { EffectiveAddresses.use_full_name }
56
+ when FalseClass
57
+ # Nothing to do
54
58
  else
55
59
  raise 'Unexpected options. Expected a Hash or Boolean'
56
60
  end
@@ -133,4 +137,3 @@ module ActsAsAddressable
133
137
  end
134
138
 
135
139
  end
136
-
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  class Address < ActiveRecord::Base
3
5
  self.table_name = EffectiveAddresses.addresses_table_name.to_s
@@ -14,10 +16,7 @@ module Effective
14
16
  full_name :string
15
17
  address1 :string
16
18
  address2 :string
17
-
18
- if EffectiveAddresses.use_address3
19
- address3 :string
20
- end
19
+ address3 :string
21
20
 
22
21
  city :string
23
22
  state_code :string
@@ -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,
@@ -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
-
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  EffectiveAddresses::Engine.routes.draw do
2
4
  scope :module => 'effective' do
3
5
  match 'addresses/subregions/:country_code', to: 'addresses#subregions', as: 'address_subregions', via: :get
@@ -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.4'.freeze
2
+ VERSION = '1.9.8'.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.4
4
+ version: 1.9.8
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: 2021-02-18 00:00:00.000000000 Z
11
+ date: 2022-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails