zipcoder 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74a116892f34cb6dbbbe40997c79d41f559068e62cf4d9635ddbc6979d6440b3
4
- data.tar.gz: f0d60ba4dc4b20a54af43f71f047be8bc1c3301923ec4e4fc769e3121d640195
3
+ metadata.gz: eac9f2d3af269299c92366bff9bcecdf96bfec2c72b54d00ceb808e6008e0d53
4
+ data.tar.gz: 01d94a09280c77d36ca2b13078de68677064cbc6c427f5b75545b47e92411160
5
5
  SHA512:
6
- metadata.gz: f9361df736ce201e9075e91d303960ff05011d08c4bfa33001fb0c1ba90724a1678064f4a6bf05a7668a70b606ca19ee83c3184f46fe052f508e67e2e3639cfd
7
- data.tar.gz: b95eae0dad1956f385a24ed2580aed23e33e4d1749425fb236a20aa9c8415d51877378460365e721e79dcc31070f33fcc486cce79ae0e4f69549e5a886692921
6
+ metadata.gz: 7084550081121cf6ca274731d3917c3c395ac2b3fb24be2c24a9d5189e02eb02fc6c1d0f728f0efb53bd8a9db6ae74f572a948932635fce8f7bb45bceea26aef
7
+ data.tar.gz: dd5512b67ad72dbed6f4166246546357272f4f2e2001668338e1b8301b4030f75e0b3e9c9bc2145ed10646ee2be1b3423a2da99efb3ca42a550646290d70e6ba
data/README.md CHANGED
@@ -7,6 +7,8 @@ Gem for performing zip code lookup operations
7
7
 
8
8
  ## Revision History
9
9
 
10
+ - v0.9.2:
11
+ - added config class
10
12
  - v0.9.1:
11
13
  - added ability to use a different data source
12
14
  - added support for data from unitestateszipcodes.org"
@@ -120,8 +122,11 @@ version. I had to use v3.3.5 to test.*
120
122
  require 'zipcoder'
121
123
  require 'zipcoder/cacher/redis'
122
124
 
123
- cacher = Zipcoder::Cacher::Redis.new(**args)
124
- Zipcoder.load_cache(cacher)
125
+ Zipcoder.config do |config|
126
+ config.cacher = Zipcoder::Cacher::Redis.new(**args)
127
+ end
128
+
129
+ Zipcoder.load_cache
125
130
  ```
126
131
 
127
132
  Please visit [Redis Github](https://github.com/redis/redis-rb) for the different options
@@ -140,7 +145,11 @@ To override the default, you can create a new YAML file with the same format as
140
145
  ```ruby
141
146
  require 'zipcoder'
142
147
 
143
- Zipcoder.load_cache(data: "path_to_data/data.yml")
148
+ Zipcoder.config do |config|
149
+ config.data = "path_to_data/data.yml"
150
+ end
151
+
152
+ Zipcoder.load_cache
144
153
  ```
145
154
 
146
155
  ##### unitestateszipcodes.org
@@ -333,7 +342,7 @@ puts "TX".state_cities names_only: true
333
342
 
334
343
  #### Method: Zipcoder.state_counties(state, **args)
335
344
 
336
- This will return the cities in a state
345
+ This will return the counties in a state
337
346
 
338
347
  **variations:**
339
348
 
@@ -10,6 +10,17 @@ module Zipcoder
10
10
  class ZipcoderError < Exception
11
11
  end
12
12
 
13
+ class Config
14
+ attr_accessor :cacher
15
+ attr_accessor :data
16
+ end
17
+
18
+ CONFIG = Config.new
19
+
20
+ def self.config(&block)
21
+ block.call(CONFIG)
22
+ end
23
+
13
24
  @@cacher = nil
14
25
  def self.cacher
15
26
  if @@cacher == nil
@@ -19,9 +30,9 @@ module Zipcoder
19
30
  end
20
31
 
21
32
  # Loads the data into memory
22
- def self.load_cache(cacher=nil, data:nil)
23
- @@cacher = cacher || Cacher::Memory.new
24
- self.cacher.load data:data
33
+ def self.load_cache
34
+ @@cacher = CONFIG.cacher || Cacher::Memory.new
35
+ self.cacher.load data: CONFIG.data
25
36
  end
26
37
 
27
38
  # Looks up zip code information
@@ -58,6 +58,7 @@ List of the states in the US
58
58
  module Zipcoder
59
59
  module Cacher
60
60
  class Base
61
+ attr_accessor :loaded
61
62
 
62
63
  KEY_BASE = "zipcoder"
63
64
  KEY_ZIP = "#{KEY_BASE}:zip"
@@ -92,9 +93,12 @@ module Zipcoder
92
93
 
93
94
  def initialize(**kwargs)
94
95
  self._init_cache **kwargs
96
+ self.loaded = false
95
97
  end
96
98
 
97
99
  def load(data: nil)
100
+ return if self.loaded
101
+
98
102
  start_time = Time.now
99
103
 
100
104
  # Load zip cache from file
@@ -166,6 +170,8 @@ module Zipcoder
166
170
 
167
171
  # Print the alpsed time
168
172
  puts "ZipCoder initialization time: #{Time.now-start_time}"
173
+
174
+ self.loaded = true
169
175
  end
170
176
 
171
177
  def read_zip_cache(zip)
@@ -1,3 +1,3 @@
1
1
  module Zipcoder
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
@@ -3,12 +3,24 @@ require "zipcoder/cacher/memory"
3
3
 
4
4
  describe Zipcoder::Cacher::Memory do
5
5
 
6
- it "allows the default data file to be overridden" do
7
-
8
- # Load the new data
6
+ before(:all) {
9
7
  new_data = "#{File.dirname(__FILE__)}/fixtures/files/temp_data.yml"
10
- Zipcoder.load_cache data: new_data
11
8
 
9
+ Zipcoder.config do |config|
10
+ config.data = new_data
11
+ end
12
+
13
+ Zipcoder.load_cache
14
+ }
15
+
16
+ after(:all) {
17
+ Zipcoder.config do |config|
18
+ config.data = nil
19
+ config.cacher = nil
20
+ end
21
+ }
22
+
23
+ it "allows the default data file to be overridden" do
12
24
  # Check that it was loaded
13
25
  expect(Zipcoder.states.count).to eq(1)
14
26
  expect("PR".state_cities.count).to eq(3)
@@ -10,12 +10,23 @@ describe Zipcoder::Cacher::Redis do
10
10
  allow(Zipcoder::Cacher::Redis).to receive(:_create_redis_client) do
11
11
  RedisStub.new
12
12
  end
13
- Zipcoder.load_cache Zipcoder::Cacher::Redis.new
13
+ Zipcoder.config do |config|
14
+ config.cacher = Zipcoder::Cacher::Redis.new
15
+ end
16
+
17
+ Zipcoder.load_cache
14
18
  end
15
19
 
16
20
  stub_redis_once = true
17
21
  end
18
22
 
23
+ after(:each) {
24
+ Zipcoder.config do |config|
25
+ config.data = nil
26
+ config.cacher = nil
27
+ end
28
+ }
29
+
19
30
  describe "#zip_info" do
20
31
  it "match" do
21
32
  info = "78748".zip_info
@@ -5,6 +5,13 @@ describe Zipcoder do
5
5
  Zipcoder.load_cache
6
6
  end
7
7
 
8
+ after(:all) {
9
+ Zipcoder.config do |config|
10
+ config.data = nil
11
+ config.cacher = nil
12
+ end
13
+ }
14
+
8
15
  it "has a version number" do
9
16
  expect(Zipcoder::VERSION).not_to be nil
10
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipcoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Chapman