heycarsten-postalcoder 0.1.4 → 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.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 1
3
- :patch: 4
2
+ :minor: 2
3
+ :patch: 0
4
4
  :major: 0
@@ -7,6 +7,7 @@ module PostalCoder
7
7
  :gmaps_api_timeout => 2,
8
8
  :tt_host => nil,
9
9
  :tt_port => 0,
10
+ :no_raise_on_connection_fail => false,
10
11
  :accepted_formats => [:ca_postal_code, :us_zip_code] }
11
12
 
12
13
  def self.merge(overrides)
@@ -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
- raise Errors::TTUnableToConnectError, 'Unable to connect to the ' \
17
- "Tokyo Tyrant server at #{@config[:tt_host]} [#{@config[:tt_port]}]"
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
- value = tyrant[key.to_s]
47
- value ? YAML.load(value) : nil
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[key.to_s] = YAML.dump(value)
52
- value # <- We don't want to return YAML in this case.
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 5, @config.size
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 5, @config.size
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
@@ -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 -79.4449720, @zip.to_hash[:point][:latitude]
50
- assert_equal 43.6504650, @zip.to_hash[:point][:longitude]
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.1.4
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-05-21 00:00:00 -07:00
12
+ date: 2009-06-15 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15