address_concern 2.0.1 → 2.1.0

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: de8b741d8cd001b4e7f4a8e12895aa623bccaabfa98dbdb41886bc25ab74e8bf
4
- data.tar.gz: 96b1e6fb186f3941ab8db185b79ad6a56be99868b9950b21742869211b4e2530
3
+ metadata.gz: 205541c7ef9aedeb7e807bb946274c5a379edc7162592bbb2b1fd1015ce681b5
4
+ data.tar.gz: 2dacfdb3da70d8ef88989ea2966e407179af9d536b8e3ae5df0826abe7ab1571
5
5
  SHA512:
6
- metadata.gz: 6a5ca29908ad512f492e510c90a1fc5c1e4ce38a3d193a9156551415da85f503bced92538edf6306615c1884bfadcae9eacffd1bb15204d4aae6cc1e1fc444c4
7
- data.tar.gz: 833b6c049415afab41e1ba8fb44cf73e69cd9392b6a9b70a0410a68f203f749f4dfd18011c6b52b711e56e3db209365be88d5e7b87d5c69c677485698e721c7f
6
+ metadata.gz: 15f9277026adf1a62dff7561386dae79d021f11eeb3f3b4c3c13ff76bb991c7893861402ad120ec7ff8a4e714fd389cb644580a1a7f2a2fedc4c273018b77c38
7
+ data.tar.gz: a5ab51814edaee41313de51bf2fc7fa75b683b79d490dc26af1401b3770c292c4ffd49b0452b3a7f02b1fd49b1d48fa2e052087d8b8e9ae43126dfa6b6fc5fe6
data/Readme.md CHANGED
@@ -6,20 +6,52 @@ 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
+ ```
10
12
 
11
- Include the `AddressConcern::Address` concern in your model:
13
+ Include the `AddressConcern::Address` concern in your app's `Address` model by adding the
14
+ `acts_as_address` macro to it:
12
15
 
13
16
  ```ruby
14
17
  class Address < ApplicationRecord
15
- include AddressConcern::Address
18
+ acts_as_address
16
19
  end
17
20
  ```
18
21
 
19
22
  Then run the generator to create your addresses table:
20
23
 
21
24
  rails generate address_concern:install
22
- rake db:migrate
25
+ rails db:migrate
26
+
27
+ You can modify the migration and add any other fields you may wish to include.
28
+
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.
35
+
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:
42
+
43
+ ```ruby
44
+ class Address < ApplicationRecord
45
+ acts_as_address(
46
+ country: {
47
+ code_attribute: :country,
48
+ },
49
+ state: {
50
+ code_attribute: :state,
51
+ },
52
+ )
53
+ end
54
+ ```
23
55
 
24
56
  # Usage
25
57
 
@@ -111,10 +143,19 @@ address = company.build_address(address: '...')
111
143
  ```
112
144
 
113
145
  This also adds a polymorphic `addressable` association on the Address model (not available if you're
114
- using `belongs_to :address` on your addressable models):
146
+ using `belongs_to_address` on your addressable models instead of `has_address`):
147
+
148
+ ```ruby
149
+ belongs_to :addressable, polymorphic: true, touch: true, optional: true
150
+ ```
115
151
 
152
+ If you wish to customize that `belongs_to`, you can pass in any options you like:
116
153
  ```ruby
117
- belongs_to :addressable, :polymorphic => true
154
+ class Address < ApplicationRecord
155
+ include AddressConcern::Address
156
+
157
+ belongs_to_addressable options…
158
+ end
118
159
  ```
119
160
 
120
161
  ## `has_addresses`
@@ -152,6 +193,32 @@ vacation_address = user.addresses.build(address: 'Vacation', :address_type => 'V
152
193
  user.addresses # => [shipping_address, vacation_address]
153
194
  ```
154
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
+
155
222
  # Country/state database
156
223
 
157
224
  Country/state data comes from the [`carmen`](https://github.com/carmen-ruby/carmen) gem.
@@ -17,10 +17,9 @@ Gem::Specification.new do |s|
17
17
  s.add_dependency "activerecord", ">= 4.0"
18
18
  s.add_dependency "activesupport", ">= 4.0"
19
19
  s.add_dependency "carmen", '>= 1.1.1'
20
- s.add_dependency "attribute_normalizer"
21
- s.add_dependency "active_record_ignored_attributes"
22
- s.add_dependency "facets"
20
+ #s.add_dependency "attribute_normalizer"
23
21
 
22
+ s.add_development_dependency 'active_record_ignored_attributes' # for be_same_as
24
23
  s.add_development_dependency 'rspec'
25
24
  s.add_development_dependency 'sqlite3'
26
25
  #s.add_development_dependency 'mysql2', '~>0.2.11'