address_concern 2.0.0 → 2.1.1

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: 54db12d5f83e9438e61c47552eba316511be4cbc69200bee3e51568a10c2c41e
4
- data.tar.gz: 73a84002eeafb49d0536d2bf5de94391410b3b4d873633ba62f2fd3e42df8ab5
3
+ metadata.gz: fd8e4df80024c5fc3a3bc5984003e412615c3d6345d8408d17859e088183e7f2
4
+ data.tar.gz: eda7df98ac44d1ecc07c7e5a0f3c4afe3c93baa53378b31cdeab6d93a19d6d34
5
5
  SHA512:
6
- metadata.gz: ac7f541ac00b56b64c9a6e8f6cc7a49ee423cce621c90a13173ddc7e4c852883d5f5a2ad14bca967b2d7c7fcc9678a7b8062bb580c30baa43bb656e681b7fed9
7
- data.tar.gz: 305160aabeca32990a9aa74aa2519b6b58b54c7354985ccbb1677fc1ec370b5c0f104319541834c33865f86079f10d4f45b31342be2d2656e90ade6eb42a85fa
6
+ metadata.gz: a09d2db18101b7b407e52481559cefd69ae17b06384e448e92b160c939d785045725e3c768156a264af182087f1a11a77f1ddc0f5b9e3a9f3202b6cfdce8d719
7
+ data.tar.gz: 7ba89fd64d9f910fe77e5b807f335c6923ca80289549a6c43afe435ed4cbad699196c75f2415f8479b474e63f86943764e881b475e1e7cb2a76fcbbd5f88ec40
data/Readme.md CHANGED
@@ -6,25 +6,55 @@ A reusable polymorphic `Address` model concern for your Rails apps.
6
6
 
7
7
  Add `address_concern` to your `Gemfile`:
8
8
 
9
- gem 'address_concern'
9
+ ```ruby
10
+ gem 'address_concern'
11
+ ```
12
+
13
+ Include the `AddressConcern::Address` concern in your app's `Address` model by adding the
14
+ `acts_as_address` macro to it:
15
+
16
+ ```ruby
17
+ class Address < ApplicationRecord
18
+ acts_as_address
19
+ end
20
+ ```
10
21
 
11
22
  Then run the generator to create your addresses table:
12
23
 
13
24
  rails generate address_concern:install
14
- rake db:migrate
25
+ rails db:migrate
15
26
 
16
- You now have an `Address` model that you can use in your app just as if it were in your `app/models` directory.
27
+ You can modify the migration and add any other fields you may wish to include.
17
28
 
18
- # Usage
29
+ For country and state/providence, you may choose to store both the code and name or just code or
30
+ just name. Remove from the migration the columns you don't need.
31
+
32
+ By default, it will store country name in `country_name` or `country` if one of those columns exist,
33
+ and store country code in `country_code` or `country` if one of those columns exist. If _only_ a
34
+ `country` column exists, it will be used to store the name attribute by default.
19
35
 
20
- ## Base usage
36
+ By default, it will store state name in `state_name` or `state` if one of those columns exist,
37
+ and store state code in `state_code` or `state` if one of those columns exist. If _only_ a
38
+ `state` column exists, it will be used to store the name attribute by default.
39
+
40
+ These column names can be configured. For example, to store country code in `country` and state code
41
+ in `state`, you could do:
21
42
 
22
43
  ```ruby
23
44
  class Address < ApplicationRecord
24
- include AddressConcern::Address
45
+ acts_as_address(
46
+ country: {
47
+ code_attribute: :country,
48
+ },
49
+ state: {
50
+ code_attribute: :state,
51
+ },
52
+ )
25
53
  end
26
54
  ```
27
55
 
56
+ # Usage
57
+
28
58
  ## `belongs_to_address`
29
59
 
30
60
  `AddressConcern::AddressAssociations` is automatically included into `ActiveRecord::Base` and
@@ -113,10 +143,19 @@ address = company.build_address(address: '...')
113
143
  ```
114
144
 
115
145
  This also adds a polymorphic `addressable` association on the Address model (not available if you're
116
- using `belongs_to :address` on your addressable models):
146
+ using `belongs_to_address` on your addressable models instead of `has_address`):
117
147
 
118
148
  ```ruby
119
- belongs_to :addressable, :polymorphic => true
149
+ belongs_to :addressable, polymorphic: true, touch: true, optional: true
150
+ ```
151
+
152
+ If you wish to customize that `belongs_to`, you can pass in any options you like:
153
+ ```ruby
154
+ class Address < ApplicationRecord
155
+ include AddressConcern::Address
156
+
157
+ belongs_to_addressable options…
158
+ end
120
159
  ```
121
160
 
122
161
  ## `has_addresses`
@@ -154,6 +193,32 @@ vacation_address = user.addresses.build(address: 'Vacation', :address_type => 'V
154
193
  user.addresses # => [shipping_address, vacation_address]
155
194
  ```
156
195
 
196
+ ## Street address
197
+
198
+ You are free to either store the street address in a single column like this:
199
+
200
+ ```ruby
201
+ create_table :addresses do |t|
202
+
203
+ t.text :address
204
+
205
+ ```
206
+
207
+ or in separate columns like this:
208
+
209
+ ```ruby
210
+ create_table :addresses do |t|
211
+
212
+ t.string :address_1
213
+ t.string :address_2
214
+ t.string :address_3
215
+
216
+ ```
217
+
218
+ If you store it in a single column of type text, then it will support multi-line addresses stored in
219
+ that single column. Calling `address.address_lines`, for example, will return an array of address
220
+ lines — however many lines the user entered (you may add validations to limit this as you wish).
221
+
157
222
  # Country/state database
158
223
 
159
224
  Country/state data comes from the [`carmen`](https://github.com/carmen-ruby/carmen) gem.
@@ -13,15 +13,14 @@ Gem::Specification.new do |s|
13
13
  s.licenses = ["MIT"]
14
14
 
15
15
  s.add_dependency "rake"
16
- s.add_dependency "cucumber"
17
16
  s.add_dependency "rails", ">= 4.0"
18
17
  s.add_dependency "activerecord", ">= 4.0"
19
18
  s.add_dependency "activesupport", ">= 4.0"
20
19
  s.add_dependency "carmen", '>= 1.1.1'
21
- s.add_dependency "attribute_normalizer"
22
- s.add_dependency "active_record_ignored_attributes"
23
- s.add_dependency "facets"
20
+ #s.add_dependency "attribute_normalizer"
21
+ s.add_dependency "zeitwerk"
24
22
 
23
+ s.add_development_dependency 'active_record_ignored_attributes' # for be_same_as
25
24
  s.add_development_dependency 'rspec'
26
25
  s.add_development_dependency 'sqlite3'
27
26
  #s.add_development_dependency 'mysql2', '~>0.2.11'
@@ -0,0 +1,3 @@
1
+ #AddressConcern.setup do |config|
2
+ # ...
3
+ #end