effective_addresses 1.9.3 → 1.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +2 -6
- data/app/helpers/effective_addresses_helper.rb +4 -5
- data/app/models/concerns/acts_as_addressable.rb +10 -7
- data/app/models/effective/address.rb +14 -17
- data/app/views/effective/addresses/_form_with.html.haml +2 -2
- data/app/views/effective/addresses/_formtastic.html.haml +1 -1
- data/app/views/effective/addresses/_simple_form.html.haml +1 -2
- data/config/routes.rb +2 -0
- data/db/migrate/01_create_effective_addresses.rb.erb +1 -3
- data/lib/effective_addresses/version.rb +1 -1
- data/lib/effective_addresses.rb +19 -14
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 662a91519afc8f6bd35398c6ef980a41d318e09b49a15da12d7572a0921d1736
|
4
|
+
data.tar.gz: c12ffecd410c02828d1d30a61198aa78e94e03d96019537930206198bf76a8ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb2dd3933ce5bfd663f4f99ad2bbf2bf2efce136a872c1b443e9ff9f96a922348b23d986260e50b05160153cc7e22911e8bb3fc8a975094949b3967c872d46e0
|
7
|
+
data.tar.gz: 1d7bc37461b4633084d2f0aa1b45a404f17b253a569a7f16e89b913c62ebd0645debe7cc413ede607109e4c34168e8f53d01291346da0016caa48205ac7305cc
|
data/MIT-LICENSE
CHANGED
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
|
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 `
|
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,15 @@
|
|
1
|
-
|
2
|
-
@@use_geocoder = defined?(Geocoder)
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
3
|
+
module EffectiveAddressesHelper
|
4
4
|
def effective_address_fields(form, method = 'billing', options = {})
|
5
5
|
method = (method.to_s.include?('_address') ? method.to_s : "#{method}_address")
|
6
6
|
|
7
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)
|
8
|
-
use_full_name = form.object._validators[method.to_sym].any? { |v| v.kind_of?(EffectiveAddressFullNamePresenceValidator) }
|
9
8
|
|
10
9
|
address = form.object.send(method) || form.object.addresses.build(category: method.to_s.gsub('_address', ''))
|
11
10
|
effective_address_pre_select(address) if address.new_record?
|
12
11
|
|
13
|
-
opts = { required: required,
|
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})
|
14
13
|
|
15
14
|
case form.class.name
|
16
15
|
when 'Effective::FormBuilder'
|
@@ -28,7 +27,7 @@ module EffectiveAddressesHelper
|
|
28
27
|
if EffectiveAddresses.pre_selected_country.present?
|
29
28
|
address.country = EffectiveAddresses.pre_selected_country
|
30
29
|
address.state = EffectiveAddresses.pre_selected_state if EffectiveAddresses.pre_selected_state.present?
|
31
|
-
elsif
|
30
|
+
elsif defined?(Geocoder) && request.location.present?
|
32
31
|
location = request.location
|
33
32
|
address.country = location.country_code
|
34
33
|
address.state = location.state_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
|
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
|
50
|
-
validates
|
51
|
-
when TrueClass
|
52
|
-
validates "#{category}_address", presence:
|
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
|
@@ -8,27 +10,22 @@ module Effective
|
|
8
10
|
|
9
11
|
belongs_to :addressable, polymorphic: true, touch: true
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
category :string
|
14
|
-
|
15
|
-
full_name :string
|
16
|
-
address1 :string
|
17
|
-
address2 :string
|
13
|
+
effective_resource do
|
14
|
+
category :string
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
full_name :string
|
17
|
+
address1 :string
|
18
|
+
address2 :string
|
19
|
+
address3 :string
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
city :string
|
22
|
+
state_code :string
|
23
|
+
country_code :string
|
24
|
+
postal_code :string
|
27
25
|
|
28
|
-
|
26
|
+
shipping_address_same_as_billing permitted: true
|
29
27
|
|
30
|
-
|
31
|
-
end
|
28
|
+
timestamps
|
32
29
|
end
|
33
30
|
|
34
31
|
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
|
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
@@ -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
|
data/lib/effective_addresses.rb
CHANGED
@@ -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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
[
|
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.
|
4
|
+
version: 1.9.7
|
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-
|
11
|
+
date: 2021-12-10 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
|