heycarsten-postalcoder 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +2 -2
- data/lib/postalcoder/config.rb +1 -0
- data/lib/postalcoder/persistence.rb +24 -6
- data/test/config_test.rb +3 -3
- data/test/geocoding_api_test.rb +2 -2
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/postalcoder/config.rb
CHANGED
@@ -13,8 +13,14 @@ module PostalCoder
|
|
13
13
|
@tyrant = Rufus::Tokyo::Tyrant.new(@config[:tt_host], @config[:tt_port])
|
14
14
|
rescue RuntimeError => boom
|
15
15
|
if boom.message.include?('couldn\'t connect to tyrant')
|
16
|
-
|
17
|
-
"
|
16
|
+
errmsg = 'Unable to connect to the Tokyo Tyrant server at ' \
|
17
|
+
"#{@config[:tt_host]} [#{@config[:tt_port]}]"
|
18
|
+
if @config[:no_raise_on_connection_fail]
|
19
|
+
@tyrant = nil
|
20
|
+
STDERR.puts("[POSTALCODER] #{errmsg}")
|
21
|
+
else
|
22
|
+
raise Errors::TTUnableToConnectError, errmsg
|
23
|
+
end
|
18
24
|
else
|
19
25
|
raise boom
|
20
26
|
end
|
@@ -43,13 +49,25 @@ module PostalCoder
|
|
43
49
|
protected
|
44
50
|
|
45
51
|
def storage_get(key)
|
46
|
-
|
47
|
-
|
52
|
+
if tyrant
|
53
|
+
value = tyrant[key.to_s]
|
54
|
+
value ? YAML.load(value) : nil
|
55
|
+
else
|
56
|
+
STDERR.puts "[POSTALCODER] Unable to get #{key.inspect} " \
|
57
|
+
'because there is no Tyrant connection.'
|
58
|
+
nil
|
59
|
+
end
|
48
60
|
end
|
49
61
|
|
50
62
|
def storage_put(key, value)
|
51
|
-
tyrant
|
52
|
-
|
63
|
+
if tyrant
|
64
|
+
tyrant[key.to_s] = YAML.dump(value)
|
65
|
+
value # <- We don't want to return YAML in this case.
|
66
|
+
else
|
67
|
+
STDERR.puts "[POSTALCODER] Unable to put #{key.inspect} " \
|
68
|
+
'because there is no Tyrant connection.'
|
69
|
+
value
|
70
|
+
end
|
53
71
|
end
|
54
72
|
|
55
73
|
def tyrant
|
data/test/config_test.rb
CHANGED
@@ -9,7 +9,7 @@ class ConfigTest < Test::Unit::TestCase
|
|
9
9
|
|
10
10
|
should 'return a hash of updated config settings' do
|
11
11
|
assert_instance_of Hash, @config
|
12
|
-
assert_equal
|
12
|
+
assert_equal 6, @config.size
|
13
13
|
assert_equal 3, @config[:gmaps_api_timeout]
|
14
14
|
end
|
15
15
|
|
@@ -25,10 +25,10 @@ class ConfigTest < Test::Unit::TestCase
|
|
25
25
|
|
26
26
|
should 'return a hash of updated config settings' do
|
27
27
|
assert_instance_of Hash, @config
|
28
|
-
assert_equal
|
28
|
+
assert_equal 6, @config.size
|
29
29
|
assert_equal 1, @config[:gmaps_api_timeout]
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
should 'change default configuration' do
|
33
33
|
assert_equal 1, PostalCoder::Config[:gmaps_api_timeout]
|
34
34
|
end
|
data/test/geocoding_api_test.rb
CHANGED
@@ -46,8 +46,8 @@ class GeocodingAPITest < Test::Unit::TestCase
|
|
46
46
|
assert_equal 'Canada', @zip.to_hash[:country][:name]
|
47
47
|
assert_equal 'CA', @zip.to_hash[:country][:code]
|
48
48
|
assert_equal 'ON', @zip.to_hash[:country][:administrative_area]
|
49
|
-
assert_equal
|
50
|
-
assert_equal
|
49
|
+
assert_equal 43.6504650, @zip.to_hash[:point][:latitude]
|
50
|
+
assert_equal -79.4449720, @zip.to_hash[:point][:longitude]
|
51
51
|
assert_equal 43.6536126, @zip.to_hash[:box][:north]
|
52
52
|
assert_equal 43.6473174, @zip.to_hash[:box][:south]
|
53
53
|
assert_equal -79.4418244, @zip.to_hash[:box][:east]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heycarsten-postalcoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Nielsen
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-15 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|