location 0.1.0 → 0.2.0
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/app/models/concerns/find_or_create.rb +20 -0
- data/app/models/location/address.rb +1 -6
- data/app/models/location/address_attributable.rb +21 -0
- data/app/models/location/address_form.rb +10 -106
- data/app/models/location/address_normalizable.rb +29 -0
- data/app/models/location/address_persistable.rb +28 -0
- data/app/models/location/address_persister.rb +52 -0
- data/app/models/location/address_validatable.rb +17 -0
- data/app/models/location/city.rb +4 -2
- data/app/models/location/district.rb +4 -2
- data/app/models/location/normalizable_address.rb +23 -0
- data/app/models/location/state.rb +4 -2
- data/db/migrate/20140223034809_rename_address_to_street.rb +5 -0
- data/lib/location.rb +4 -4
- data/lib/location/address_normalizer.rb +78 -0
- data/lib/location/finder.rb +14 -14
- data/lib/location/services/stubbed_service.rb +9 -12
- data/lib/location/services/uni5.rb +2 -2
- data/lib/location/version.rb +1 -1
- metadata +62 -33
- data/app/models/location/form.rb +0 -55
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ec5da426070f00af7462e481cc7a3875b20d04b
|
4
|
+
data.tar.gz: 8db38ffe3f9756df01c3c2a936d97435d8fd44dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03e96a958095e5839bfda023f814848958b33eee8f05820751b43f5b8313a781e713b1c47b092be8ad8baccad636b93218dcd474f0d85dba42bd75fb0b44e035
|
7
|
+
data.tar.gz: 0efbafdc4015d8ed4778b09ab10cf5b17c55f172f5b829f8add24e82f393f6a20a0696ae6caf0fff9f3e3221ba29b395a7c84c7915dfa7d93b89482a69842f16
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Location
|
2
|
+
module FindOrCreate
|
3
|
+
def find_or_save!(attributes)
|
4
|
+
attributes = self.attributes.select { |k| k =~ /_id$/ }
|
5
|
+
.merge(attributes)
|
6
|
+
|
7
|
+
if attributes[:normalized]
|
8
|
+
object = self.class.find_by(attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
if object
|
12
|
+
object
|
13
|
+
else
|
14
|
+
self.attributes = attributes
|
15
|
+
save!
|
16
|
+
self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -7,18 +7,13 @@ module Location
|
|
7
7
|
|
8
8
|
before_save :format_postal_code
|
9
9
|
|
10
|
-
validates :address, length: { maximum: 150 }
|
11
|
-
validates :number, length: { maximum: 20 }
|
12
|
-
validates :complement, length: { maximum: 40 }
|
13
|
-
validates :latitude, :longitude, numericality: true, allow_blank: true
|
14
|
-
|
15
10
|
scope :full, ->{ eager_load(:district).eager_load(:city).eager_load(:state) }
|
16
11
|
default_scope { full }
|
17
12
|
|
18
13
|
def to_hash
|
19
14
|
{
|
20
15
|
postal_code: self.postal_code,
|
21
|
-
|
16
|
+
street: self.street,
|
22
17
|
number: self.number,
|
23
18
|
complement: self.complement,
|
24
19
|
district: self.district.try(:name),
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Location
|
2
|
+
module AddressAttributable
|
3
|
+
fields = %i{postal_code street number complement
|
4
|
+
district city state latitude longitude}
|
5
|
+
|
6
|
+
fields.each do |field|
|
7
|
+
attr_writer field
|
8
|
+
|
9
|
+
define_method field do
|
10
|
+
instance_value = instance_variable_get("@#{field}")
|
11
|
+
|
12
|
+
if instance_value.nil? && respond_to?(:address) && !address.nil?
|
13
|
+
value = address.send(field)
|
14
|
+
value.respond_to?(:name) ? value.name : value
|
15
|
+
else
|
16
|
+
instance_value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,19 +1,20 @@
|
|
1
1
|
require 'super_form'
|
2
|
+
require 'location/address_validatable'
|
3
|
+
require 'location/address_normalizable'
|
4
|
+
require 'location/address_persister'
|
2
5
|
|
3
6
|
module Location
|
4
7
|
class AddressForm
|
5
8
|
include SuperForm
|
6
|
-
|
7
|
-
|
8
|
-
%i{state city district}
|
9
|
-
end
|
9
|
+
include AddressValidatable
|
10
|
+
include AddressNormalizable
|
10
11
|
|
11
12
|
def self.default_presence_attributes
|
12
|
-
%i{postal_code
|
13
|
+
%i{postal_code street district}
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.string_attributes
|
16
|
-
%i{postal_code
|
17
|
+
%i{postal_code street number complement district city state}
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.float_attributes
|
@@ -27,44 +28,15 @@ module Location
|
|
27
28
|
validates attr, presence: true, if: ->(a){ a.presence[attr] }
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
-
validate :ensure_find_address
|
32
|
-
before_save :normalize_attributes!
|
33
|
-
|
34
|
-
attr_accessor :model
|
31
|
+
attr_accessor :address
|
35
32
|
|
36
33
|
def presence
|
37
34
|
@presence || validate_presence_of(AddressForm.default_presence_attributes)
|
38
35
|
end
|
39
36
|
|
40
|
-
def address_attributes
|
41
|
-
attributes = %w{postal_code address number complement latitude longitude}
|
42
|
-
values_for_attributes(attributes)
|
43
|
-
end
|
44
|
-
|
45
|
-
def normalized_attributes=(attributes)
|
46
|
-
@normalized_attributes = Array(attributes)
|
47
|
-
ensure_valid_normalized_attributes!
|
48
|
-
end
|
49
|
-
|
50
|
-
def normalized_attributes
|
51
|
-
@normalized_attributes ||= Location.configuration.normalized_fields
|
52
|
-
ensure_valid_normalized_attributes!
|
53
|
-
@normalized_attributes
|
54
|
-
end
|
55
|
-
|
56
|
-
def ensure_valid_normalized_attributes!
|
57
|
-
unless valid_normalized_attributes?
|
58
|
-
raise ::StandardError.new, "Invalid normalizable attributes"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def attribute_normalized?(attr)
|
63
|
-
normalized_attributes.include?(attr)
|
64
|
-
end
|
65
|
-
|
66
37
|
def validate_presence_of(attributes)
|
67
38
|
attributes = Array(attributes)
|
39
|
+
|
68
40
|
@presence = self.attributes.keys.inject({}) do |hash, attr|
|
69
41
|
hash[attr] = attributes.include?(attr)
|
70
42
|
hash
|
@@ -73,76 +45,8 @@ module Location
|
|
73
45
|
|
74
46
|
private
|
75
47
|
|
76
|
-
def valid_normalized_attributes?
|
77
|
-
valid = self.class.normalizable_attributes.slice(0, @normalized_attributes.count)
|
78
|
-
valid == @normalized_attributes || valid.reverse == @normalized_attributes
|
79
|
-
end
|
80
|
-
|
81
48
|
def persist!
|
82
|
-
|
83
|
-
if @model.try(:persisted?)
|
84
|
-
update
|
85
|
-
else
|
86
|
-
create
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def create
|
92
|
-
state = create_attribute(:state, State)
|
93
|
-
city = create_attribute(:city, state.cities)
|
94
|
-
district = create_attribute(:district, city.districts)
|
95
|
-
|
96
|
-
@model = district.addresses.create!(address_attributes)
|
97
|
-
end
|
98
|
-
|
99
|
-
def update
|
100
|
-
@model.update(address_attributes)
|
101
|
-
|
102
|
-
district = update_attribute(@model, :district)
|
103
|
-
city = update_attribute(district, :city)
|
104
|
-
|
105
|
-
update_attribute(city, :state)
|
106
|
-
end
|
107
|
-
|
108
|
-
def update_attribute(parent, attr)
|
109
|
-
child = parent.send(attr) || parent.send("build_#{attr.to_s}")
|
110
|
-
child.update(attributes_for(attr))
|
111
|
-
child
|
112
|
-
end
|
113
|
-
|
114
|
-
def attributes_for(attr)
|
115
|
-
{ name: send(attr), normalized: attribute_normalized?(attr) }
|
116
|
-
end
|
117
|
-
|
118
|
-
def create_attribute(attr, klass)
|
119
|
-
attrs = attributes_for(attr)
|
120
|
-
method = attrs[:normalized] ? "first_or_create!" : "create!"
|
121
|
-
klass.send(method, attrs)
|
122
|
-
end
|
123
|
-
|
124
|
-
def build_finder
|
125
|
-
@finder = Finder.build(postal_code)
|
126
|
-
end
|
127
|
-
|
128
|
-
def ensure_find_address
|
129
|
-
@finder.find do |f|
|
130
|
-
unless f.successful?
|
131
|
-
errors.add :postal_code, %{Can't find address for #{postal_code}}
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def normalize_attributes!
|
137
|
-
normalized_attributes.each do |f|
|
138
|
-
send("#{f}=", @finder.address.send(f))
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def values_for_attributes(attributes)
|
143
|
-
attributes.each_with_object({}) do |attr, hash|
|
144
|
-
hash[attr] = send(attr)
|
145
|
-
end
|
49
|
+
AddressPersister.new(address_normalizer, address).persist!
|
146
50
|
end
|
147
51
|
end
|
148
52
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'location/address_normalizer'
|
3
|
+
|
4
|
+
module Location
|
5
|
+
module AddressNormalizable
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
before_save :normalize_attributes!
|
10
|
+
end
|
11
|
+
|
12
|
+
def normalizable_address_attributes=(attributes)
|
13
|
+
address_normalizer.normalizable = attributes
|
14
|
+
end
|
15
|
+
|
16
|
+
def address_normalizer
|
17
|
+
(@normalizers ||= {})[postal_code] ||= Location::AddressNormalizer.new(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def normalize_attributes!
|
23
|
+
unless address_normalizer.normalize!
|
24
|
+
errors.add :postal_code, %{Can't find address for #{postal_code}}
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'location/address_attributable'
|
3
|
+
require 'location/address_validatable'
|
4
|
+
require 'location/address_normalizable'
|
5
|
+
|
6
|
+
module Location
|
7
|
+
module AddressPersistable
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
attr_writer :address_persister
|
11
|
+
|
12
|
+
included do
|
13
|
+
include Location::AddressAttributable
|
14
|
+
include Location::AddressValidatable
|
15
|
+
include Location::AddressNormalizable
|
16
|
+
|
17
|
+
before_save :persist_address!
|
18
|
+
end
|
19
|
+
|
20
|
+
def address_persister
|
21
|
+
@address_persister ||= AddressPersister.new(address_normalizer, address)
|
22
|
+
end
|
23
|
+
|
24
|
+
def persist_address!
|
25
|
+
address_persister.persist!
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Location
|
2
|
+
class AddressPersister
|
3
|
+
attr_reader :normalizer, :address
|
4
|
+
|
5
|
+
def initialize(normalizer, address)
|
6
|
+
@normalizer = normalizer
|
7
|
+
@address = address
|
8
|
+
end
|
9
|
+
|
10
|
+
def persist!
|
11
|
+
State.transaction(requires_new: true) do
|
12
|
+
if @address && @address.persisted?
|
13
|
+
update
|
14
|
+
else
|
15
|
+
create
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def create
|
23
|
+
state = create_attribute(:state, State.new)
|
24
|
+
city = create_attribute(:city, state.cities.build)
|
25
|
+
district = create_attribute(:district, city.districts.build)
|
26
|
+
|
27
|
+
@address = district.addresses.create!(@normalizer.attributes)
|
28
|
+
@normalizer.address = @address
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_attribute(attribute, object)
|
32
|
+
attributes = @normalizer.parameterize_attribute(attribute)
|
33
|
+
object.find_or_save!(attributes)
|
34
|
+
end
|
35
|
+
|
36
|
+
def update
|
37
|
+
@address.update(@normalizer.attributes)
|
38
|
+
|
39
|
+
district = update_attribute(@address, :district)
|
40
|
+
city = update_attribute(district, :city)
|
41
|
+
|
42
|
+
update_attribute(city, :state)
|
43
|
+
end
|
44
|
+
|
45
|
+
def update_attribute(parent, attr)
|
46
|
+
child = parent.send(attr) || parent.send("build_#{attr.to_s}")
|
47
|
+
attributes = @normalizer.parameterize_attribute(attr)
|
48
|
+
child.update(attributes)
|
49
|
+
child
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Location
|
4
|
+
module AddressValidatable
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
validates :street, length: { maximum: 150 }
|
9
|
+
validates :number, length: { maximum: 20 }
|
10
|
+
validates :complement, length: { maximum: 40 }
|
11
|
+
validates :latitude, :longitude, numericality: true, allow_blank: true
|
12
|
+
validates :district, length: { maximum: 150 }
|
13
|
+
validates :city, length: { maximum: 150 }
|
14
|
+
validates :state, length: { maximum: 150 }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/app/models/location/city.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Location
|
2
|
+
class NormalizableAddress < Address
|
3
|
+
include Location::AddressValidatable
|
4
|
+
include Location::AddressNormalizable
|
5
|
+
|
6
|
+
attr_accessor :district_name, :city_name, :state_name
|
7
|
+
|
8
|
+
before_create :persist_address!
|
9
|
+
after_update :persist_address!
|
10
|
+
|
11
|
+
def address_persister
|
12
|
+
@address_persister ||= AddressPersister.new(address_normalizer, self, true)
|
13
|
+
end
|
14
|
+
|
15
|
+
def persist_address!
|
16
|
+
address_persister.persist!
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.inheritance_column
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
require 'concerns/find_or_create'
|
2
|
+
|
1
3
|
module Location
|
2
4
|
class State < ActiveRecord::Base
|
5
|
+
include FindOrCreate
|
6
|
+
|
3
7
|
has_many :cities, dependent: :destroy
|
4
8
|
has_many :districts, through: :cities
|
5
9
|
has_many :addresses, through: :districts
|
6
|
-
|
7
|
-
validates :name, length: { maximum: 150 }
|
8
10
|
end
|
9
11
|
end
|
data/lib/location.rb
CHANGED
@@ -19,14 +19,14 @@ module Location
|
|
19
19
|
class Configuration
|
20
20
|
attr_accessor :default_service
|
21
21
|
attr_accessor :service_options
|
22
|
-
attr_accessor :
|
23
|
-
attr_accessor :
|
22
|
+
attr_accessor :concat_type_to_street
|
23
|
+
attr_accessor :normalizable_attributes
|
24
24
|
|
25
25
|
def initialize
|
26
26
|
@default_service = Services::Republica
|
27
27
|
@service_options = {}
|
28
|
-
@
|
29
|
-
@
|
28
|
+
@concat_type_to_street = false
|
29
|
+
@normalizable_attributes = %i{state city}
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'location/finder'
|
3
|
+
|
4
|
+
module Location
|
5
|
+
class AddressNormalizer
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
def self.allowed_for_normalization
|
9
|
+
%i{state city district}
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.default_normalizable
|
13
|
+
Location.configuration.normalizable_attributes
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :model
|
17
|
+
def_delegators :model, :address, :address=
|
18
|
+
|
19
|
+
def initialize(model)
|
20
|
+
@model = model
|
21
|
+
end
|
22
|
+
|
23
|
+
def normalize!
|
24
|
+
Finder.find(@model.postal_code) do |finder|
|
25
|
+
return false unless finder.successful?
|
26
|
+
|
27
|
+
normalizable.each do |a|
|
28
|
+
value = finder.address.send(a)
|
29
|
+
@model.send("#{a}=", value) unless value.nil?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def normalizable=(attributes)
|
35
|
+
@normalizable = Array(attributes)
|
36
|
+
ensure_valid_normalizable!
|
37
|
+
end
|
38
|
+
|
39
|
+
def normalizable
|
40
|
+
@normalizable ||= self.class.default_normalizable
|
41
|
+
ensure_valid_normalizable!
|
42
|
+
|
43
|
+
@normalizable
|
44
|
+
end
|
45
|
+
|
46
|
+
def normalizable?(attribute)
|
47
|
+
normalizable.include?(attribute)
|
48
|
+
end
|
49
|
+
|
50
|
+
def attributes
|
51
|
+
attributes = %w{postal_code street number complement latitude longitude}
|
52
|
+
|
53
|
+
attributes.each_with_object({}) do |attr, hash|
|
54
|
+
hash[attr] = @model.send(attr)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def parameterize_attribute(attribute)
|
59
|
+
{
|
60
|
+
name: @model.send(attribute),
|
61
|
+
normalized: normalizable?(attribute)
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def ensure_valid_normalizable!
|
68
|
+
unless valid_normalizable?
|
69
|
+
raise ::StandardError.new, "Invalid normalizable attributes"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def valid_normalizable?
|
74
|
+
valid = self.class.allowed_for_normalization.slice(0, @normalizable.count)
|
75
|
+
valid == @normalizable || valid.reverse == @normalizable
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/location/finder.rb
CHANGED
@@ -13,8 +13,8 @@ module Location
|
|
13
13
|
|
14
14
|
def initialize(postal_code, service)
|
15
15
|
@postal_code = postal_code
|
16
|
-
@service
|
17
|
-
@address
|
16
|
+
@service = service
|
17
|
+
@address = Address.new
|
18
18
|
end
|
19
19
|
|
20
20
|
def find
|
@@ -34,17 +34,17 @@ module Location
|
|
34
34
|
|
35
35
|
class Address
|
36
36
|
attr_accessor :type, :postal_code
|
37
|
-
attr_accessor :
|
37
|
+
attr_accessor :street, :number, :complement
|
38
38
|
attr_accessor :district, :city, :state
|
39
39
|
|
40
40
|
def type=(type)
|
41
41
|
@type = type
|
42
|
-
|
42
|
+
concat_type_to_street
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
46
|
-
@
|
47
|
-
|
45
|
+
def street=(street)
|
46
|
+
@street = street
|
47
|
+
concat_type_to_street
|
48
48
|
end
|
49
49
|
|
50
50
|
def to_hash(options = {})
|
@@ -61,17 +61,17 @@ module Location
|
|
61
61
|
|
62
62
|
private
|
63
63
|
|
64
|
-
def
|
65
|
-
|
64
|
+
def concat_type_to_street
|
65
|
+
concat_type_to_street! if concat_type_to_street?
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
69
|
-
Location.configuration.
|
70
|
-
!type.nil? && !
|
68
|
+
def concat_type_to_street?
|
69
|
+
Location.configuration.concat_type_to_street &&
|
70
|
+
!type.nil? && !street.nil?
|
71
71
|
end
|
72
72
|
|
73
|
-
def
|
74
|
-
@
|
73
|
+
def concat_type_to_street!
|
74
|
+
@street = "#{type} #{street}"
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
@@ -1,23 +1,20 @@
|
|
1
1
|
module Location
|
2
2
|
module Services
|
3
3
|
class StubbedService
|
4
|
-
|
5
|
-
|
4
|
+
def self.attributes
|
5
|
+
@attributes ||= {}
|
6
6
|
end
|
7
7
|
|
8
|
-
def self.attributes
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
city: 'Rio de Janeiro',
|
15
|
-
state: 'RJ'
|
16
|
-
}
|
8
|
+
def self.set_result(postal_code, attributes)
|
9
|
+
self.attributes[postal_code] ||= attributes
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.attributes_for(postal_code)
|
13
|
+
self.attributes[postal_code] || {}
|
17
14
|
end
|
18
15
|
|
19
16
|
def fetch(postal_code, address)
|
20
|
-
|
17
|
+
self.class.attributes_for(postal_code).each do |k, v|
|
21
18
|
address.send("#{k}=", v)
|
22
19
|
end
|
23
20
|
end
|
@@ -15,7 +15,7 @@ module Location
|
|
15
15
|
address.city = res['cidade']
|
16
16
|
address.district = res['bairro']
|
17
17
|
address.type = res['tipo_logradouro']
|
18
|
-
address.
|
18
|
+
address.street = res['logradouro']
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -38,7 +38,7 @@ module Location
|
|
38
38
|
end
|
39
39
|
|
40
40
|
yield eval_result(response.body)
|
41
|
-
rescue Net::HTTPBadResponse
|
41
|
+
rescue Net::HTTPBadResponse
|
42
42
|
raise Error.new, 'Got a bad response'
|
43
43
|
rescue SocketError
|
44
44
|
raise Error.new, 'Got a socket error'
|
data/lib/location/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: location
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thiago A. Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -17,9 +17,6 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.0'
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 4.0.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,37 +24,62 @@ dependencies:
|
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '4.0'
|
30
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: super_form
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
33
41
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
42
|
+
name: virtus
|
35
43
|
requirement: !ruby/object:Gem::Requirement
|
36
44
|
requirements:
|
37
45
|
- - '='
|
38
46
|
- !ruby/object:Gem::Version
|
39
|
-
version: 1.
|
40
|
-
type: :
|
47
|
+
version: 1.0.1
|
48
|
+
type: :runtime
|
41
49
|
prerelease: false
|
42
50
|
version_requirements: !ruby/object:Gem::Requirement
|
43
51
|
requirements:
|
44
52
|
- - '='
|
45
53
|
- !ruby/object:Gem::Version
|
46
|
-
version: 1.
|
54
|
+
version: 1.0.1
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
56
|
+
name: activemodel
|
49
57
|
requirement: !ruby/object:Gem::Requirement
|
50
58
|
requirements:
|
51
|
-
- -
|
59
|
+
- - '='
|
52
60
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
61
|
+
version: 4.0.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.0.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.8
|
54
76
|
type: :development
|
55
77
|
prerelease: false
|
56
78
|
version_requirements: !ruby/object:Gem::Requirement
|
57
79
|
requirements:
|
58
|
-
- -
|
80
|
+
- - '='
|
59
81
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
82
|
+
version: 1.3.8
|
61
83
|
- !ruby/object:Gem::Dependency
|
62
84
|
name: rspec-rails
|
63
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,20 +164,6 @@ dependencies:
|
|
142
164
|
- - '='
|
143
165
|
- !ruby/object:Gem::Version
|
144
166
|
version: 1.16.1
|
145
|
-
- !ruby/object:Gem::Dependency
|
146
|
-
name: virtus
|
147
|
-
requirement: !ruby/object:Gem::Requirement
|
148
|
-
requirements:
|
149
|
-
- - '='
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
version: 1.0.1
|
152
|
-
type: :development
|
153
|
-
prerelease: false
|
154
|
-
version_requirements: !ruby/object:Gem::Requirement
|
155
|
-
requirements:
|
156
|
-
- - '='
|
157
|
-
- !ruby/object:Gem::Version
|
158
|
-
version: 1.0.1
|
159
167
|
- !ruby/object:Gem::Dependency
|
160
168
|
name: pry-rails
|
161
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,6 +206,20 @@ dependencies:
|
|
198
206
|
- - '='
|
199
207
|
- !ruby/object:Gem::Version
|
200
208
|
version: 0.8.2
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: awesome_print
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - "~>"
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: 1.2.0
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - "~>"
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 1.2.0
|
201
223
|
description: Polymorphic address models, address normalization, address web services,
|
202
224
|
address autocomplete, maps
|
203
225
|
email:
|
@@ -213,11 +235,17 @@ files:
|
|
213
235
|
- app/controllers/location/application_controller.rb
|
214
236
|
- app/controllers/location/finder_controller.rb
|
215
237
|
- app/helpers/location/application_helper.rb
|
238
|
+
- app/models/concerns/find_or_create.rb
|
216
239
|
- app/models/location/address.rb
|
240
|
+
- app/models/location/address_attributable.rb
|
217
241
|
- app/models/location/address_form.rb
|
242
|
+
- app/models/location/address_normalizable.rb
|
243
|
+
- app/models/location/address_persistable.rb
|
244
|
+
- app/models/location/address_persister.rb
|
245
|
+
- app/models/location/address_validatable.rb
|
218
246
|
- app/models/location/city.rb
|
219
247
|
- app/models/location/district.rb
|
220
|
-
- app/models/location/
|
248
|
+
- app/models/location/normalizable_address.rb
|
221
249
|
- app/models/location/state.rb
|
222
250
|
- app/views/layouts/location/application.html.erb
|
223
251
|
- app/views/location/finder/show.js.coffee
|
@@ -233,7 +261,9 @@ files:
|
|
233
261
|
- db/migrate/20140129154554_add_normalized_to_states.rb
|
234
262
|
- db/migrate/20140129154726_add_normalized_to_cities.rb
|
235
263
|
- db/migrate/20140129154734_add_normalized_to_districts.rb
|
264
|
+
- db/migrate/20140223034809_rename_address_to_street.rb
|
236
265
|
- lib/location.rb
|
266
|
+
- lib/location/address_normalizer.rb
|
237
267
|
- lib/location/engine.rb
|
238
268
|
- lib/location/finder.rb
|
239
269
|
- lib/location/services/errors.rb
|
@@ -264,9 +294,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
264
294
|
version: '0'
|
265
295
|
requirements: []
|
266
296
|
rubyforge_project:
|
267
|
-
rubygems_version: 2.2.
|
297
|
+
rubygems_version: 2.2.2
|
268
298
|
signing_key:
|
269
299
|
specification_version: 4
|
270
300
|
summary: Location and address related utilities
|
271
301
|
test_files: []
|
272
|
-
has_rdoc:
|
data/app/models/location/form.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'virtus'
|
2
|
-
|
3
|
-
module Location
|
4
|
-
module Form
|
5
|
-
def self.included(klass)
|
6
|
-
virtus = @virtus_options ?
|
7
|
-
Virtus.model(@virtus_options) :
|
8
|
-
Virtus.model
|
9
|
-
|
10
|
-
klass.include virtus
|
11
|
-
klass.include ActiveModel::Conversion
|
12
|
-
klass.include ActiveModel::Validations
|
13
|
-
klass.extend ActiveModel::Naming
|
14
|
-
klass.extend ActiveModel::Callbacks
|
15
|
-
|
16
|
-
add_callbacks(klass)
|
17
|
-
|
18
|
-
@virtus_options = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.add_callbacks(klass)
|
22
|
-
klass.class_eval do
|
23
|
-
alias_method :ar_valid?, :valid?
|
24
|
-
|
25
|
-
def valid?
|
26
|
-
run_callbacks :validation do
|
27
|
-
ar_valid?
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
define_model_callbacks :validation, :save
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.base(virtus_options = {})
|
36
|
-
@virtus_options = virtus_options
|
37
|
-
Form
|
38
|
-
end
|
39
|
-
|
40
|
-
def persisted?
|
41
|
-
false
|
42
|
-
end
|
43
|
-
|
44
|
-
def save
|
45
|
-
if valid?
|
46
|
-
run_callbacks :save do
|
47
|
-
persist!
|
48
|
-
end
|
49
|
-
true
|
50
|
-
else
|
51
|
-
false
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|