magic_addresses 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +37 -2
- data/app/models/magic_addresses/address.rb +3 -11
- data/app/models/magic_addresses/association.rb +35 -15
- data/app/models/magic_addresses/country.rb +5 -0
- data/app/models/magic_addresses/district.rb +4 -0
- data/app/models/magic_addresses/state.rb +4 -0
- data/app/models/magic_addresses/subdistrict.rb +2 -0
- data/lib/generators/magic_addresses/templates/magic_addresses_migration.rb +1 -10
- data/lib/generators/magic_addresses/templates/magic_initializer.rb +0 -2
- data/lib/helpers/mgca_helper.rb +6 -13
- data/lib/magic_addresses/configuration.rb +0 -2
- data/lib/magic_addresses/version.rb +1 -1
- data/spec/dummy/config/initializers/magic_addresses.rb +0 -2
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/{20150223223200_add_magic_addresses.rb → 20150225220219_add_magic_addresses.rb} +1 -10
- data/spec/dummy/db/schema.rb +1 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +3729 -0
- data/spec/dummy/log/test.log +37882 -0
- data/spec/models/magic_addresses/address_spec.rb +171 -0
- data/spec/models/magic_addresses/association_spec.rb +93 -8
- metadata +4 -28
- data/app/models/concerns/address_builder.rb +0 -169
- data/app/models/concerns/has_address.rb +0 -67
- data/app/models/location/address.rb +0 -111
- data/app/models/location/city.rb +0 -39
- data/app/models/location/country.rb +0 -39
- data/app/models/location/district.rb +0 -37
- data/app/models/location/state.rb +0 -39
- data/app/models/location/subdistrict.rb +0 -38
- data/app/services/geo_coder.rb +0 -46
- data/lib/generators/magic_addresses/templates/location_addresses_migration.rb +0 -157
- data/spec/models/concerns/has_address_spec.rb +0 -92
- data/spec/models/location/address_spec.rb +0 -227
- data/spec/models/location/city_spec.rb +0 -27
- data/spec/models/location/country_spec.rb +0 -26
- data/spec/models/location/state_spec.rb +0 -27
- data/spec/models/location/subcity_spec.rb +0 -26
- data/spec/models/location/subsubcity_spec.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afae17ac192fd28b6715937a4a9d213298b208a1
|
4
|
+
data.tar.gz: 884a80a98cc530e7d53f128d9c0d96b22d269536
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c6854f10dedc764d2a539bbdff5dbb03c5cc56c95a3f0b0e0db40984926653b5f514a9982743ae86775560cf433b681b408603197ee6d1943012a49c68407f9
|
7
|
+
data.tar.gz: 943f8b826fbedb192e86d60a34195142fa17a966f39b6fd6ea4d25157eb381aedf8781d7631bc2aa7466289208a6f9bc5091fd134ecbe84e1398e73441821def
|
data/README.md
CHANGED
@@ -25,12 +25,47 @@ rails g magic_addresses:install
|
|
25
25
|
# You can use `has_one_address` and `has_addresses` on the same model
|
26
26
|
# `has_one_address` sets the default flag so could be major address.
|
27
27
|
|
28
|
-
|
29
|
-
# in Progress
|
30
28
|
has_nested_address # => Has one directly nested addresses. (ie: User.street, User.city)
|
31
29
|
|
32
30
|
```
|
33
31
|
|
32
|
+
#### View Mehtods
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
|
36
|
+
<%= country_flag( :de, "small" ) %>
|
37
|
+
# flag helper for all default countries ( "small" | "medium" | "large")
|
38
|
+
|
39
|
+
<%= render "magic_addresses/addresses/fields/address", f: f %>
|
40
|
+
# form helper for 'has_one_address'
|
41
|
+
|
42
|
+
```
|
43
|
+
|
44
|
+
#### in your Controllers:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Never trust parameters from the scary internet! ... has_one_address
|
51
|
+
def instance_params
|
52
|
+
params.require(:instance).permit( .. :address_attributes => [:id, :street, :number, :postalcode, :city, :country, :_destroy] .. )
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# Never trust parameters from the scary internet! ... has_addresses
|
57
|
+
def instance_params
|
58
|
+
params.require(:instance).permit( .. :addresses_attributes => [:id, :street, :number, :postalcode, :city, :country, :_destroy] .. )
|
59
|
+
end
|
60
|
+
|
61
|
+
- or -
|
62
|
+
|
63
|
+
:address_attributes => MagicAddresses::Address::PARAMS # has_one_address
|
64
|
+
:addresses_attributes => MagicAddresses::Address::PARAMS # has_addresses
|
65
|
+
|
66
|
+
```
|
67
|
+
|
68
|
+
|
34
69
|
|
35
70
|
#### Structure
|
36
71
|
|
@@ -6,6 +6,8 @@ class MagicAddresses::Address < ActiveRecord::Base
|
|
6
6
|
|
7
7
|
|
8
8
|
# =====> C O N S T A N T S <=============================================================== #
|
9
|
+
PARAMS = [ :id, :street, :street_additional, :number, :postalcode, :city, :country, :owner, :_destroy ]
|
10
|
+
|
9
11
|
|
10
12
|
# =====> A S S O Z I A T I O N S <========================================================= #
|
11
13
|
belongs_to :owner, polymorphic: true
|
@@ -28,15 +30,9 @@ class MagicAddresses::Address < ActiveRecord::Base
|
|
28
30
|
|
29
31
|
|
30
32
|
# =====> A T T R I B U T E S <============================================================= #
|
31
|
-
|
32
|
-
# setup hstore
|
33
|
-
store_accessor :fetch_address # , :fetch_street, :fetch_number, :fetch_city, :fetch_zipcode, :fetch_country
|
34
|
-
else
|
35
|
-
serialize :fetch_address, Hash
|
36
|
-
end
|
33
|
+
serialize :fetch_address, Hash
|
37
34
|
|
38
35
|
%w[fetch_street fetch_number fetch_city fetch_zipcode fetch_country].each do |key|
|
39
|
-
# attr_accessor key
|
40
36
|
define_method(key) do
|
41
37
|
fetch_address && fetch_address[key]
|
42
38
|
end
|
@@ -44,7 +40,6 @@ class MagicAddresses::Address < ActiveRecord::Base
|
|
44
40
|
self.fetch_address = (fetch_address || {}).merge(key => value)
|
45
41
|
end
|
46
42
|
end
|
47
|
-
|
48
43
|
# attr_accessor :street
|
49
44
|
def street
|
50
45
|
fetch_address && fetch_address["fetch_street"] || street_name
|
@@ -53,7 +48,6 @@ class MagicAddresses::Address < ActiveRecord::Base
|
|
53
48
|
self.street_name = value
|
54
49
|
self.fetch_address = (fetch_address || {}).merge("fetch_street" => value)
|
55
50
|
end
|
56
|
-
|
57
51
|
# attr_accessor :number (:street_number)
|
58
52
|
def number
|
59
53
|
fetch_address && fetch_address["fetch_number"] || street_number
|
@@ -61,7 +55,6 @@ class MagicAddresses::Address < ActiveRecord::Base
|
|
61
55
|
def number=(value)
|
62
56
|
self.fetch_address = (fetch_address || {}).merge("fetch_number" => value)
|
63
57
|
end
|
64
|
-
|
65
58
|
# attr_accessor :postalcode (:zipcode)
|
66
59
|
def postalcode
|
67
60
|
fetch_address && fetch_address["fetch_zipcode"] || zipcode
|
@@ -70,7 +63,6 @@ class MagicAddresses::Address < ActiveRecord::Base
|
|
70
63
|
self.fetch_address = (fetch_address || {}).merge("fetch_zipcode" => value)
|
71
64
|
end
|
72
65
|
|
73
|
-
|
74
66
|
%w[country state city district subdistrict].each do |key|
|
75
67
|
# attr_accessor key
|
76
68
|
define_method(key) do
|
@@ -8,32 +8,52 @@ module MagicAddresses
|
|
8
8
|
|
9
9
|
## C L A S S - M E T H O D S # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
10
10
|
module ClassMethods
|
11
|
-
|
11
|
+
|
12
|
+
|
12
13
|
def has_addresses
|
13
|
-
|
14
|
-
|
14
|
+
has_many :addresses,
|
15
|
+
as: :owner,
|
16
|
+
class_name: "MagicAddresses::Address",
|
17
|
+
dependent: :destroy
|
15
18
|
accepts_nested_attributes_for :addresses, allow_destroy: true, reject_if: :all_blank
|
16
19
|
end
|
17
20
|
|
21
|
+
|
18
22
|
def has_one_address
|
19
23
|
has_one :address, -> { where(default: true) },
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
as: :owner,
|
25
|
+
class_name: "MagicAddresses::Address",
|
26
|
+
autosave: true,
|
27
|
+
dependent: :destroy
|
28
|
+
accepts_nested_attributes_for :address, allow_destroy: true, reject_if: :all_blank
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def has_nested_address
|
33
|
+
send :include, InstanceMethods
|
34
|
+
has_one :address,
|
35
|
+
as: :owner,
|
36
|
+
class_name: "MagicAddresses::Address",
|
37
|
+
autosave: true,
|
38
|
+
dependent: :destroy
|
39
|
+
delegate :street, :number, :postalcode, :city, :district, :subdistrict, :state, :country,
|
40
|
+
:street=, :number=, :postalcode=, :city=, :country=,
|
41
|
+
to: :address, allow_nil: true
|
42
|
+
accepts_nested_attributes_for :address, allow_destroy: true, reject_if: :all_blank
|
43
|
+
alias_method_chain :address, :build
|
27
44
|
end
|
28
|
-
|
29
|
-
|
45
|
+
|
46
|
+
|
30
47
|
end #> ClassMethods
|
31
48
|
|
32
49
|
## I N S T A N C E - M E T H O D S # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
33
50
|
module InstanceMethods
|
34
|
-
|
35
|
-
#
|
36
|
-
|
51
|
+
|
52
|
+
# http://stackoverflow.com/a/4033761
|
53
|
+
def address_with_build
|
54
|
+
self.address_without_build || self.build_address
|
55
|
+
end
|
56
|
+
|
37
57
|
end #> InstanceMethods
|
38
58
|
|
39
59
|
end
|
@@ -4,6 +4,11 @@ class MagicAddresses::Country < ActiveRecord::Base
|
|
4
4
|
# =====> A S S O Z I A T I O N S <========================================================= #
|
5
5
|
has_many :addresses, class_name: "MagicAddresses::Address", foreign_key: :country_id
|
6
6
|
|
7
|
+
has_many :states, class_name: "MagicAddresses::State", foreign_key: :country_id
|
8
|
+
has_many :cities, through: :states, source: :cities
|
9
|
+
has_many :districts, through: :cities, source: :districts
|
10
|
+
has_many :subdistricts, through: :districts, source: :subdistricts
|
11
|
+
|
7
12
|
|
8
13
|
# =====> A T T R I B U T E S <============================================================= #
|
9
14
|
mgca_translate :name
|
@@ -6,6 +6,10 @@ class MagicAddresses::District < ActiveRecord::Base
|
|
6
6
|
|
7
7
|
belongs_to :city, class_name: "MagicAddresses::City", foreign_key: :city_id
|
8
8
|
|
9
|
+
has_one :state, through: :city, source: :state
|
10
|
+
has_one :country, through: :state, source: :country
|
11
|
+
|
12
|
+
has_many :subdistricts, class_name: "MagicAddresses::District", foreign_key: :district_id
|
9
13
|
|
10
14
|
# =====> A T T R I B U T E S <============================================================= #
|
11
15
|
mgca_translate :name
|
@@ -6,6 +6,10 @@ class MagicAddresses::State < ActiveRecord::Base
|
|
6
6
|
|
7
7
|
belongs_to :country, class_name: "MagicAddresses::Country", foreign_key: :country_id
|
8
8
|
|
9
|
+
has_many :cities, class_name: "MagicAddresses::City", foreign_key: :state_id
|
10
|
+
has_many :districts, through: :cities, source: :districts
|
11
|
+
has_many :subdistricts, through: :districts, source: :subdistricts
|
12
|
+
|
9
13
|
|
10
14
|
# =====> A T T R I B U T E S <============================================================= #
|
11
15
|
mgca_translate :name
|
@@ -7,6 +7,8 @@ class MagicAddresses::Subdistrict < ActiveRecord::Base
|
|
7
7
|
belongs_to :city, class_name: "MagicAddresses::City", foreign_key: :city_id
|
8
8
|
belongs_to :district, class_name: "MagicAddresses::District", foreign_key: :district_id
|
9
9
|
|
10
|
+
has_one :state, through: :city, source: :state
|
11
|
+
has_one :country, through: :state, source: :country
|
10
12
|
|
11
13
|
# =====> A T T R I B U T E S <============================================================= #
|
12
14
|
mgca_translate :name
|
@@ -3,8 +3,6 @@ class AddMagicAddresses < ActiveRecord::Migration
|
|
3
3
|
def up
|
4
4
|
|
5
5
|
# if using with postgresql
|
6
|
-
# => # add hstore extensions
|
7
|
-
# => enable_extension "hstore"
|
8
6
|
# => # add extensions for distance calculation
|
9
7
|
# => enable_extension "cube"
|
10
8
|
# => enable_extension "earthdistance"
|
@@ -16,12 +14,7 @@ class AddMagicAddresses < ActiveRecord::Migration
|
|
16
14
|
|
17
15
|
t.string :name # => name (if needed)
|
18
16
|
|
19
|
-
#
|
20
|
-
if MagicAddresses.configuration.hstore
|
21
|
-
t.hstore :fetch_address # => hstore method
|
22
|
-
else
|
23
|
-
t.text :fetch_address # => default serialize field
|
24
|
-
end
|
17
|
+
t.text :fetch_address # => default serialize field
|
25
18
|
|
26
19
|
# t.string :street
|
27
20
|
t.string :street_default
|
@@ -199,8 +192,6 @@ class AddMagicAddresses < ActiveRecord::Migration
|
|
199
192
|
# => # disable extensions for distance calculation
|
200
193
|
# => disable_extension "earthdistance"
|
201
194
|
# => disable_extension "cube"
|
202
|
-
# => # disable hstore extension
|
203
|
-
# => disable_extension "hstore"
|
204
195
|
|
205
196
|
end
|
206
197
|
end
|
data/lib/helpers/mgca_helper.rb
CHANGED
@@ -2,18 +2,11 @@ require "action_view/helpers/asset_tag_helper"
|
|
2
2
|
|
3
3
|
# encoding: utf-8
|
4
4
|
module MgcaHelper
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def country_flag( lcl = I18n.locale.to_s, format = "small" )
|
13
|
-
format = "medium" unless %w(small medium large).include?(format)
|
14
|
-
lcl = "xx" unless %w(at by be ba bg ca hr cy cz dk fi fr de gr hu ie it lv li lt lu nl no pl pt ro ru rs sk si es se ch ua gb us).include?( lcl.to_s.downcase )
|
15
|
-
raw( image_tag( "flags/countries/#{format}/flag-#{lcl.to_s.downcase}.png", class: "flag" ) )
|
16
|
-
end
|
17
|
-
|
5
|
+
|
6
|
+
def country_flag( lcl = I18n.locale.to_s, format = "small" )
|
7
|
+
format = "medium" unless %w(small medium large).include?(format)
|
8
|
+
lcl = "xx" unless %w(at by be ba bg ca hr cy cz dk fi fr de gr hu ie it lv li lt lu nl no pl pt ro ru rs sk si es se ch ua gb us).include?( lcl.to_s.downcase )
|
9
|
+
raw( image_tag( "flags/countries/#{format}/flag-#{lcl.to_s.downcase}.png", class: "flag" ) )
|
10
|
+
end
|
18
11
|
|
19
12
|
end
|
@@ -14,7 +14,6 @@ module MagicAddresses
|
|
14
14
|
attr_accessor :job_backend
|
15
15
|
|
16
16
|
attr_accessor :earthdistance
|
17
|
-
attr_accessor :hstore
|
18
17
|
|
19
18
|
def initialize
|
20
19
|
@active_locales = [:en, :de]
|
@@ -22,7 +21,6 @@ module MagicAddresses
|
|
22
21
|
@default_country = "Germany"
|
23
22
|
@job_backend = :none
|
24
23
|
@earthdistance = false
|
25
|
-
@hstore = false
|
26
24
|
end
|
27
25
|
|
28
26
|
# Returns a hash of all configurable options
|
Binary file
|
@@ -3,8 +3,6 @@ class AddMagicAddresses < ActiveRecord::Migration
|
|
3
3
|
def up
|
4
4
|
|
5
5
|
# if using with postgresql
|
6
|
-
# => # add hstore extensions
|
7
|
-
# => enable_extension "hstore"
|
8
6
|
# => # add extensions for distance calculation
|
9
7
|
# => enable_extension "cube"
|
10
8
|
# => enable_extension "earthdistance"
|
@@ -16,12 +14,7 @@ class AddMagicAddresses < ActiveRecord::Migration
|
|
16
14
|
|
17
15
|
t.string :name # => name (if needed)
|
18
16
|
|
19
|
-
#
|
20
|
-
if MagicAddresses.configuration.hstore
|
21
|
-
t.hstore :fetch_address # => hstore method
|
22
|
-
else
|
23
|
-
t.text :fetch_address # => default serialize field
|
24
|
-
end
|
17
|
+
t.text :fetch_address # => default serialize field
|
25
18
|
|
26
19
|
# t.string :street
|
27
20
|
t.string :street_default
|
@@ -199,8 +192,6 @@ class AddMagicAddresses < ActiveRecord::Migration
|
|
199
192
|
# => # disable extensions for distance calculation
|
200
193
|
# => disable_extension "earthdistance"
|
201
194
|
# => disable_extension "cube"
|
202
|
-
# => # disable hstore extension
|
203
|
-
# => disable_extension "hstore"
|
204
195
|
|
205
196
|
end
|
206
197
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20150225220219) do
|
15
15
|
|
16
16
|
create_table "mgca_address_translations", force: :cascade do |t|
|
17
17
|
t.integer "mgca_address_id", null: false
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|