location 0.0.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d5e6cb904c7136f83a2944efe05be72b4da98191
4
- data.tar.gz: a9288f769f3f4ee55dc8f89fb5dcf6e5942b5060
3
+ metadata.gz: f41922279600670cf0eda74410ac5c15252ef970
4
+ data.tar.gz: 9090ba682f5b4f59662fa9f6380d265bf881fcbc
5
5
  SHA512:
6
- metadata.gz: 171da40227393a64a0624aa167b4e1b46ec2fb03443074267e049e273c1fcd6d9d43c5f8e8f113222f455f460636b9e22cadfa9e7aef82384010e206b82db20a
7
- data.tar.gz: f76b33b5e2c321898165a6ae01287a91c029c9ae7ee61da0fe8803e79232240d7dd9fa399e3920810e6e713b296e4da290b98aac4d0899d67a4bc5c5d3b1c729
6
+ metadata.gz: a7214776f86d06f7b71a0beafba8bfb53ae758e95e23441921b657af8e5a01513f11fe8a62bf921c0f16ea461e8b39bdd206212f8ca3935dd9224303c3a4f5eb
7
+ data.tar.gz: 00e312c8dbb1fa5a20049887b0250e6c2de7e23dc579d65409a18bb3e321179a756dff9e36d245a207469c1fc2ee12c81e609647fe238677b5c744c1ee320f0a
@@ -4,7 +4,7 @@ module Location
4
4
 
5
5
  def show
6
6
  Finder.find params[:postal_code] do |f|
7
- @address = f.address.to_json
7
+ @address = f.address.to_hash(only: params[:only]).to_json
8
8
  end
9
9
  end
10
10
  end
@@ -1,13 +1,15 @@
1
+ require 'super_form'
2
+
1
3
  module Location
2
4
  class AddressForm
3
- include Form
5
+ include SuperForm
4
6
 
5
7
  def self.normalizable_attributes
6
8
  %i{state city district}
7
9
  end
8
10
 
9
11
  def self.default_presence_attributes
10
- %i{postal_code address district city state}
12
+ %i{postal_code address district}
11
13
  end
12
14
 
13
15
  def self.string_attributes
@@ -18,8 +20,8 @@ module Location
18
20
  %i{latitude longitude}
19
21
  end
20
22
 
21
- string_attributes.each { |attr| attribute attr, String }
22
- float_attributes.each { |attr| attribute attr, Float }
23
+ string_attributes.each { |attr| field attr, Field::Text }
24
+ float_attributes.each { |attr| field attr, Field::Float }
23
25
 
24
26
  (string_attributes + float_attributes).each do |attr|
25
27
  validates attr, presence: true, if: ->(a){ a.presence[attr] }
@@ -99,7 +101,8 @@ module Location
99
101
 
100
102
  district = update_attribute(@model, :district)
101
103
  city = update_attribute(district, :city)
102
- state = update_attribute(city, :state)
104
+
105
+ update_attribute(city, :state)
103
106
  end
104
107
 
105
108
  def update_attribute(parent, attr)
@@ -47,6 +47,18 @@ module Location
47
47
  concat_type_to_address
48
48
  end
49
49
 
50
+ def to_hash(options = {})
51
+ attributes = instance_variables.map do |k|
52
+ k.to_s.gsub(/^@/, '').to_sym
53
+ end
54
+
55
+ only = Array(options[:only] || attributes).map!(&:to_sym)
56
+
57
+ attributes.each_with_object({}) do |k, a|
58
+ a[k] = send(k) if only.include?(k)
59
+ end
60
+ end
61
+
50
62
  private
51
63
 
52
64
  def concat_type_to_address
@@ -40,6 +40,8 @@ module Location
40
40
  yield eval_result(response.body)
41
41
  rescue Net::HTTPBadResponse => e
42
42
  raise Error.new, 'Got a bad response'
43
+ rescue SocketError
44
+ raise Error.new, 'Got a socket error'
43
45
  end
44
46
 
45
47
  def eval_result(json)
@@ -1,3 +1,3 @@
1
1
  module Location
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
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.0.1
4
+ version: 0.1.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-02-05 00:00:00.000000000 Z
11
+ date: 2014-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - '='
45
45
  - !ruby/object:Gem::Version
46
46
  version: 1.3.8
47
+ - !ruby/object:Gem::Dependency
48
+ name: super_form
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.1'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.1'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: rspec-rails
49
63
  requirement: !ruby/object:Gem::Requirement