effective_addresses 1.7.3 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3376de3376b723d9fbe00ce43d7b6b99360afee9
4
- data.tar.gz: e8cfb0a633cfd35f16090be9c95130b7d7a95440
3
+ metadata.gz: 1e242bd222bdf45a2b873aea1cb4a99966fbd3d7
4
+ data.tar.gz: 510cde83910aee2c94fda85928003375da8bf9e5
5
5
  SHA512:
6
- metadata.gz: b35f500058ff20a3e79f5b0b79d685e86be98d1cb326283c46c87d04943d2330bef950b0c8b33a5ca962dabb36887a8ef60a66d948573e27bbfdedd62c3b8ebd
7
- data.tar.gz: 3ec0d596f357b3bc4f9d6aee60123740833f23a988fadfcd8ecd304aad9919dd766b71dda29c2b7526d37d48661a769d3c39bffc459768dbf96b1c7a8c4575d7
6
+ metadata.gz: a2ddc40defbc7a58d324f33e83329e3ee6b133eebf2542e44d605c973a38f11f861156362dc93ebd4e33fce0a061f2a41322038301260dcc0dfc2d3f112ef438
7
+ data.tar.gz: 4ce4c776b7ab5a11c985005151ff0522dee5440938675cefd7b415c0d30c8909725aca9d828954091b038f85297ff8b89e49e1321e72ce5e4e4c80763642cf5d
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2014 Code and Effect Inc.
1
+ Copyright 2017 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
@@ -6,9 +6,9 @@ module Effective
6
6
  @subregions = Carmen::Country.coded(params[:country_code]).try(:subregions)
7
7
 
8
8
  if @subregions.present?
9
- render :partial => 'effective/addresses/subregions'
9
+ render partial: 'effective/addresses/subregions'
10
10
  else
11
- render :body => "<option value=''>None Available</option>"
11
+ render body: "<option value=''>None Available</option>"
12
12
  end
13
13
  end
14
14
  end
@@ -11,7 +11,7 @@ module ActsAsAddressable
11
11
  end
12
12
 
13
13
  included do
14
- has_many :addresses, as: :addressable, class_name: 'Effective::Address', dependent: :delete_all, autosave: true
14
+ has_many :addresses, -> { order(:updated_at) }, as: :addressable, class_name: 'Effective::Address', dependent: :delete_all, autosave: true
15
15
 
16
16
  # Normalize categories
17
17
  categories = @acts_as_addressable_opts.try(:flatten) || []
@@ -58,13 +58,6 @@ module ActsAsAddressable
58
58
 
59
59
  if ((categories.try(:keys) rescue nil) || categories).include?('billing') && ((categories.try(:keys) rescue nil) || categories).include?('shipping')
60
60
  self.send(:define_method, :shipping_address_same_as_billing?) { billing_address == shipping_address }
61
-
62
- before_validation do
63
- if @_effective_addresses_shipping_address_same_as_billing
64
- self.shipping_address = self.billing_address
65
- end
66
- end
67
-
68
61
  end
69
62
 
70
63
  end
@@ -81,58 +74,54 @@ module ActsAsAddressable
81
74
  effective_addresses(category).last
82
75
  end
83
76
 
84
- def set_effective_address(category, atts)
85
- unless (atts.kind_of?(Effective::Address) || atts.kind_of?(Hash) || atts == nil)
86
- raise ArgumentError.new("Effective::Address #{category}_address= expecting an Effective::Address or Hash of attributes")
87
- end
77
+ def set_effective_address(category, obj)
78
+ raise "#{category}_address= expected an Effective::Address or Hash" unless obj.kind_of?(Effective::Address) || obj.kind_of?(Hash)
88
79
 
89
- atts = HashWithIndifferentAccess.new(atts.kind_of?(Effective::Address) ? atts.attributes : atts)
90
-
91
- return if atts[:address1].blank?
92
-
93
- add = Effective::Address.new(
94
- :category => category.to_s,
95
- :full_name => atts[:full_name],
96
- :address1 => atts[:address1],
97
- :address2 => atts[:address2],
98
- :city => atts[:city],
99
- :state_code => atts[:state_code],
100
- :country_code => atts[:country_code],
101
- :postal_code => atts[:postal_code],
102
- :shipping_address_same_as_billing => atts[:shipping_address_same_as_billing]
103
- )
104
-
105
- if category == 'shipping' && add.shipping_address_same_as_billing?
106
- @_effective_addresses_shipping_address_same_as_billing = true
107
- return
80
+ address = (obj.kind_of?(Effective::Address) ? obj : Effective::Address.new(obj))
81
+
82
+ if category == 'shipping' && address.shipping_address_same_as_billing? && respond_to?(:billing_address)
83
+ address = effective_address('billing')
108
84
  end
109
85
 
110
- self.addresses.build(add.attributes) unless (add == effective_address(category))
111
- end
86
+ # Prevents duplicates from being created
87
+ return effective_address(category) if address == effective_address(category)
112
88
 
113
- def set_singular_effective_address(category, atts)
114
- raise ArgumentError.new("Effective::Address #{category}_address= expecting an Effective::Address or Hash of attributes") unless (atts.kind_of?(Effective::Address) || atts.kind_of?(Hash) || atts == nil)
89
+ (self.addresses.build).tap do |existing|
90
+ existing.category = category.to_s
91
+ existing.full_name = address.full_name
92
+ existing.address1 = address.address1
93
+ existing.address2 = address.address2
94
+ existing.city = address.city
95
+ existing.state_code = address.state_code
96
+ existing.country_code = address.country_code
97
+ existing.postal_code = address.postal_code
98
+ existing.shipping_address_same_as_billing = address.shipping_address_same_as_billing?
99
+ end
100
+ end
115
101
 
116
- atts = HashWithIndifferentAccess.new(atts.kind_of?(Effective::Address) ? atts.attributes : atts)
102
+ def set_singular_effective_address(category, obj)
103
+ raise "#{category}_address= expected an Effective::Address or Hash" unless obj.kind_of?(Effective::Address) || obj.kind_of?(Hash)
117
104
 
118
- return if atts[:address1].blank?
105
+ address = (obj.kind_of?(Effective::Address) ? obj : Effective::Address.new(obj))
119
106
 
120
- add = (effective_address(category) || self.addresses.build()).tap do |existing|
121
- existing.category = category.to_s
122
- existing.full_name = atts[:full_name]
123
- existing.address1 = atts[:address1]
124
- existing.address2 = atts[:address2]
125
- existing.city = atts[:city]
126
- existing.state_code = atts[:state_code]
127
- existing.country_code = atts[:country_code]
128
- existing.postal_code = atts[:postal_code]
129
- existing.shipping_address_same_as_billing = atts[:shipping_address_same_as_billing]
107
+ if category == 'shipping' && address.shipping_address_same_as_billing? && respond_to?(:billing_address)
108
+ address = effective_address('billing')
130
109
  end
131
110
 
132
- if category == 'shipping' && add.shipping_address_same_as_billing?
133
- @_effective_addresses_shipping_address_same_as_billing = true
134
- end
111
+ # This wouldn't create duplicates anyway
112
+ return effective_address(category) if address == effective_address(category)
135
113
 
114
+ (effective_address(category) || self.addresses.build).tap do |existing|
115
+ existing.category = category.to_s
116
+ existing.full_name = address.full_name
117
+ existing.address1 = address.address1
118
+ existing.address2 = address.address2
119
+ existing.city = address.city
120
+ existing.state_code = address.state_code
121
+ existing.country_code = address.country_code
122
+ existing.postal_code = address.postal_code
123
+ existing.shipping_address_same_as_billing = address.shipping_address_same_as_billing?
124
+ end
136
125
  end
137
126
 
138
127
  end
@@ -21,8 +21,7 @@ module Effective
21
21
  :allow_blank => true, # We're already checking for presence above
22
22
  :message => 'is an invalid United States zip code'
23
23
 
24
- default_scope -> { order(:updated_at) }
25
-
24
+ scope :sorted, -> { order(:updated_at) }
26
25
  scope :billing, -> { where(:category => 'billing') }
27
26
  scope :shipping, -> { where(:category => 'shipping') }
28
27
 
@@ -124,9 +123,9 @@ module Effective
124
123
 
125
124
  def shipping_address_same_as_billing?
126
125
  if defined?(::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES) # Rails 5
127
- ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(self.shipping_address_same_as_billing)
126
+ ::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(shipping_address_same_as_billing)
128
127
  else
129
- ActiveRecord::Type::Boolean.new.cast(self.shipping_address_same_as_billing)
128
+ ActiveRecord::Type::Boolean.new.cast(shipping_address_same_as_billing)
130
129
  end
131
130
  end
132
131
  end
@@ -33,7 +33,7 @@ EffectiveAddresses.setup do |config|
33
33
  config.simple_form_options = {}
34
34
 
35
35
  # config.simple_form_options = {
36
- # :html => {:class => 'form-horizontal'},
36
+ # :html => {:class => ['form-horizontal']},
37
37
  # :wrapper => :horizontal_form,
38
38
  # :wrapper_mappings => {
39
39
  # :boolean => :horizontal_boolean,
@@ -20,7 +20,7 @@ module EffectiveAddresses
20
20
  end
21
21
 
22
22
  # Set up our default configuration options.
23
- initializer "effective_addresses.defaults", :before => :load_config_initializers do |app|
23
+ initializer 'effective_addresses.defaults', before: :load_config_initializers do |app|
24
24
  eval File.read("#{config.root}/config/effective_addresses.rb")
25
25
  end
26
26
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveAddresses
2
- VERSION = '1.7.3'.freeze
2
+ VERSION = '1.7.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.7.3
4
+ version: 1.7.4
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: 2017-06-15 00:00:00.000000000 Z
11
+ date: 2017-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -62,7 +62,6 @@ extra_rdoc_files: []
62
62
  files:
63
63
  - MIT-LICENSE
64
64
  - README.md
65
- - Rakefile
66
65
  - app/assets/javascripts/effective_addresses.js
67
66
  - app/assets/javascripts/effective_addresses/address_fields.js.coffee
68
67
  - app/assets/javascripts/effective_addresses/shipping_address_same_as_billing.js.coffee
@@ -84,7 +83,6 @@ files:
84
83
  - lib/effective_addresses/engine.rb
85
84
  - lib/effective_addresses/version.rb
86
85
  - lib/generators/effective_addresses/install_generator.rb
87
- - lib/tasks/effective_addresses_tasks.rake
88
86
  - spec/controllers/addresses_controller_spec.rb
89
87
  - spec/dummy/README.rdoc
90
88
  - spec/dummy/Rakefile
data/Rakefile DELETED
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
-
8
- # Our tasks
9
- load 'lib/tasks/effective_addresses_tasks.rake'
10
-
11
- # Testing tasks
12
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
13
- load 'rails/tasks/engine.rake'
14
-
15
- Bundler::GemHelper.install_tasks
16
-
17
- require 'rspec/core'
18
- require 'rspec/core/rake_task'
19
-
20
- desc "Run all specs in spec directory (excluding plugin specs)"
21
- RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
22
-
23
- task :default => :spec
@@ -1,4 +0,0 @@
1
- #desc "Explaining what the task does"
2
- # task :effective_address_task do
3
- # puts "okay"
4
- # end