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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e41141e340c412a2e083dfb79792a86f102484fe61734eebf85963ba17c287c8
4
- data.tar.gz: f0f60629f50f7f20e3e8ba6976e6ba9554b18ed6bb38870a4653ab1ad33b9c17
3
+ metadata.gz: 662a91519afc8f6bd35398c6ef980a41d318e09b49a15da12d7572a0921d1736
4
+ data.tar.gz: c12ffecd410c02828d1d30a61198aa78e94e03d96019537930206198bf76a8ab
5
5
  SHA512:
6
- metadata.gz: 934bf8000a28eb370e5f444d6f70610ea7b63f5c0d71c0e1da9f1ed0d83265b697b424489b732d2469e3a23edde57c603d11b2daf2aec9a4688635239e45ee4d
7
- data.tar.gz: 170e98c482c1d99e3907864773762f487f0b61b0e5fc8399ffcac6c11f4d03655b547450d0c7a8ae856b97a7b13469bbe83f7a602ad8304b9ae32397f9f82179
6
+ metadata.gz: fb2dd3933ce5bfd663f4f99ad2bbf2bf2efce136a872c1b443e9ff9f96a922348b23d986260e50b05160153cc7e22911e8bb3fc8a975094949b3967c872d46e0
7
+ data.tar.gz: 1d7bc37461b4633084d2f0aa1b45a404f17b253a569a7f16e89b913c62ebd0645debe7cc413ede607109e4c34168e8f53d01291346da0016caa48205ac7305cc
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,15 @@
1
- module EffectiveAddressesHelper
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, 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})
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 @@use_geocoder && request.location.present?
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, :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
@@ -8,27 +10,22 @@ module Effective
8
10
 
9
11
  belongs_to :addressable, polymorphic: true, touch: true
10
12
 
11
- if defined?(EffectiveResources)
12
- effective_resource do
13
- category :string
14
-
15
- full_name :string
16
- address1 :string
17
- address2 :string
13
+ effective_resource do
14
+ category :string
18
15
 
19
- if EffectiveAddresses.use_address3
20
- address3 :string
21
- end
16
+ full_name :string
17
+ address1 :string
18
+ address2 :string
19
+ address3 :string
22
20
 
23
- city :string
24
- state_code :string
25
- country_code :string
26
- postal_code :string
21
+ city :string
22
+ state_code :string
23
+ country_code :string
24
+ postal_code :string
27
25
 
28
- shipping_address_same_as_billing permitted: true
26
+ shipping_address_same_as_billing permitted: true
29
27
 
30
- timestamps
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 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.3'.freeze
2
+ VERSION = '1.9.7'.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.3
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-02-03 00:00:00.000000000 Z
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