vin_exploder 0.4.8 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +19 -0
- data/lib/vin_exploder/cache/couchrest_cache_store.rb +1 -1
- data/lib/vin_exploder/cache/em_synchrony_couchdb_cache_store.rb +36 -0
- data/lib/vin_exploder/cache.rb +2 -2
- data/lib/vin_exploder/configuration.rb +1 -1
- data/lib/vin_exploder/version.rb +1 -1
- data/spec/cache/couchrest_cache_store_spec.rb +34 -37
- data/spec/cache/em_synchrony_couchdb_cache_store_spec.rb +63 -0
- metadata +37 -37
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3863f0fb2ecdb65ce7d0d29bd855e2e9291c1ea8
|
4
|
+
data.tar.gz: 04018344c735677ee4279ad3692c42517c868598
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 570b6f0009aed3daa067a2d3e0794faca768b5c70d8df848f1f7f545bc5240641b9228f5b63f0b2a16fb47e754c93f7cdd5e9ff26c029b5754034b618dabc826
|
7
|
+
data.tar.gz: bda7aafff83f771ee4a4e13425eec27b2efae6b85a42f353af59a8eea7ed1fd8bcdf3f2f57b4c9951396a304dc71df4963d4341bec6ca1c9ba479c482f783554
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -16,13 +16,31 @@ GEM
|
|
16
16
|
arel (~> 2.0.10)
|
17
17
|
tzinfo (~> 0.3.23)
|
18
18
|
activesupport (3.0.9)
|
19
|
+
addressable (2.3.5)
|
19
20
|
arel (2.0.10)
|
20
21
|
builder (2.1.2)
|
22
|
+
cookiejar (0.3.0)
|
21
23
|
couchrest (1.0.2)
|
22
24
|
json (~> 1.5.1)
|
23
25
|
mime-types (~> 1.15)
|
24
26
|
rest-client (~> 1.6.1)
|
25
27
|
diff-lcs (1.1.3)
|
28
|
+
em-http-request (1.1.0)
|
29
|
+
addressable (>= 2.3.4)
|
30
|
+
cookiejar
|
31
|
+
em-socksify (>= 0.3)
|
32
|
+
eventmachine (>= 1.0.3)
|
33
|
+
http_parser.rb (>= 0.6.0.beta.2)
|
34
|
+
em-socksify (0.3.0)
|
35
|
+
eventmachine (>= 1.0.0.beta.4)
|
36
|
+
em-synchrony (1.0.3)
|
37
|
+
eventmachine (>= 1.0.0.beta.1)
|
38
|
+
em-synchrony-couchdb (0.1.1)
|
39
|
+
em-http-request (>= 1.1.0)
|
40
|
+
em-synchrony (>= 1.0.3)
|
41
|
+
json (>= 1.4.3)
|
42
|
+
eventmachine (1.0.3)
|
43
|
+
http_parser.rb (0.6.0.beta.2)
|
26
44
|
i18n (0.5.0)
|
27
45
|
json (1.5.3)
|
28
46
|
mime-types (1.16)
|
@@ -49,6 +67,7 @@ PLATFORMS
|
|
49
67
|
DEPENDENCIES
|
50
68
|
activerecord (>= 3.0.0)
|
51
69
|
couchrest
|
70
|
+
em-synchrony-couchdb (= 0.1.1)
|
52
71
|
rspec (>= 2.11.1)
|
53
72
|
sequel
|
54
73
|
simplecov
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'em-synchrony/couchdb'
|
2
|
+
|
3
|
+
module VinExploder
|
4
|
+
module Cache
|
5
|
+
|
6
|
+
class EMSynchronyCouchDBCacheStore < Store
|
7
|
+
def initialize(options={})
|
8
|
+
@db_name = options.delete(:db_name)
|
9
|
+
@db = EM::Synchrony::CouchDB.new options
|
10
|
+
|
11
|
+
@db.create_db(@db_name) unless @db.get_all_dbs.include?(@db_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def read(vin)
|
15
|
+
key = make_vin_cache_key(vin)
|
16
|
+
result = @db.get(@db_name, key)['data']
|
17
|
+
symbolize_result_hash(result)
|
18
|
+
rescue
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def write(vin, hash)
|
23
|
+
key = make_vin_cache_key(vin)
|
24
|
+
@db.save(@db_name, "_id" => key, :data => hash)
|
25
|
+
hash
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete(vin)
|
29
|
+
key = make_vin_cache_key(vin)
|
30
|
+
result = @db.delete(@db_name, @db.get(@db_name, key))
|
31
|
+
!result.nil? && result['ok']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/vin_exploder/cache.rb
CHANGED
@@ -36,7 +36,7 @@ module VinExploder
|
|
36
36
|
hash = read(vin)
|
37
37
|
if block_given?
|
38
38
|
if hash.nil?
|
39
|
-
hash = yield
|
39
|
+
hash = yield
|
40
40
|
# adapter should raise exception on error but in case it doesn't don't write to cache
|
41
41
|
write(vin, hash) unless hash.empty? || (hash[:errors] && !hash[:errors].empty?)
|
42
42
|
end
|
@@ -79,4 +79,4 @@ module VinExploder
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
end
|
82
|
+
end
|
data/lib/vin_exploder/version.rb
CHANGED
@@ -6,51 +6,48 @@ module VinExploder
|
|
6
6
|
module Cache
|
7
7
|
|
8
8
|
describe CouchrestCacheStore do
|
9
|
+
let(:db_name) { 'vindecoder_test' }
|
10
|
+
let(:options) { {:host => 'http://localhost:5984', :db_name => db_name} }
|
11
|
+
let(:store) { CouchrestCacheStore.new options }
|
12
|
+
let(:vin) { '3D7LU38C83G854645' }
|
13
|
+
let(:doc) { {:vin => vin, :make => 'Ford' } }
|
14
|
+
|
9
15
|
before(:each) do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@db.delete! if @db rescue nil
|
14
|
-
|
15
|
-
@store = CouchrestCacheStore.new(db_config)
|
16
|
+
srv = CouchRest.new options[:host]
|
17
|
+
db = srv.database(options[:db_name])
|
18
|
+
db.delete! if db rescue nil
|
16
19
|
end
|
17
|
-
|
20
|
+
|
18
21
|
it "should initialize" do
|
19
|
-
|
22
|
+
store.class.should == CouchrestCacheStore
|
20
23
|
end
|
21
|
-
|
24
|
+
|
22
25
|
it "should read and write a hash" do
|
23
|
-
vin
|
24
|
-
|
25
|
-
|
26
|
-
@store.write(vin, {:vin => vin, :make => 'Ford'})
|
27
|
-
hash = @store.read(vin)
|
28
|
-
hash.should_not be_nil
|
29
|
-
hash[:make].should == 'Ford'
|
26
|
+
store.read(vin).should be_nil
|
27
|
+
store.write(vin, doc)
|
28
|
+
store.read(vin).should == doc
|
30
29
|
end
|
31
|
-
|
32
|
-
it "should fetch and cache new vins" do
|
33
|
-
hash = @store.fetch(:fake_vin_number) do
|
34
|
-
{:vin => 'fake_vin_number', :make => 'Ford'}
|
35
|
-
end
|
36
|
-
hash2 = @store.read(:fake_vin_number)
|
37
|
-
hash[:vin].should == hash2[:vin]
|
38
|
-
end
|
39
|
-
|
30
|
+
|
40
31
|
it "should delete a vin from the cache" do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
32
|
+
store.write(vin, doc)
|
33
|
+
store.read(vin).should == doc
|
34
|
+
store.delete(vin).should be_true
|
35
|
+
store.read(vin).should be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should use the value provided by the block if the vin is not in the cache" do
|
39
|
+
store.read(vin).should be_nil
|
40
|
+
store.fetch(vin) { doc }
|
41
|
+
store.read(vin).should == doc
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should not yield to the block if the vin is already in the cache" do
|
45
|
+
store.write(vin, doc)
|
46
|
+
expect{|b|
|
47
|
+
store.fetch(vin, &b)
|
48
|
+
}.not_to yield_control
|
51
49
|
end
|
52
|
-
|
53
50
|
end
|
54
51
|
|
55
52
|
end
|
56
|
-
end
|
53
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'vin_exploder/cache/em_synchrony_couchdb_cache_store'
|
3
|
+
|
4
|
+
module VinExploder
|
5
|
+
module Cache
|
6
|
+
|
7
|
+
describe EMSynchronyCouchDBCacheStore do
|
8
|
+
let(:db_name) { 'vindecoder_test' }
|
9
|
+
let(:options) { {:host => 'localhost', :port => 5984, :db_name => db_name} }
|
10
|
+
let(:store) { EMSynchronyCouchDBCacheStore.new options }
|
11
|
+
let(:vin) { '3D7LU38C83G854645' }
|
12
|
+
let(:doc) { {:vin => vin, :make => 'Ford' } }
|
13
|
+
|
14
|
+
def with_synchrony(&test)
|
15
|
+
EM.synchrony do
|
16
|
+
test.call
|
17
|
+
EM.stop
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
before do
|
22
|
+
with_synchrony do
|
23
|
+
EM::Synchrony::CouchDB.connect(options).delete_db(db_name)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should read and write a hash" do
|
28
|
+
with_synchrony do
|
29
|
+
store.read(vin).should be_nil
|
30
|
+
store.write(vin, doc)
|
31
|
+
store.read(vin).should == doc
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should delete a vin from the cache" do
|
36
|
+
with_synchrony do
|
37
|
+
store.write(vin, doc)
|
38
|
+
store.read(vin).should == doc
|
39
|
+
store.delete(vin).should be_true
|
40
|
+
store.read(vin).should be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should use the value provided by the block if the vin is not in the cache" do
|
45
|
+
with_synchrony do
|
46
|
+
store.read(vin).should be_nil
|
47
|
+
store.fetch(vin) { doc }
|
48
|
+
store.read(vin).should == doc
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not yield to the block if the vin is already in the cache" do
|
53
|
+
with_synchrony do
|
54
|
+
store.write(vin, doc)
|
55
|
+
expect{|b|
|
56
|
+
store.fetch(vin, &b)
|
57
|
+
}.not_to yield_control
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
metadata
CHANGED
@@ -1,112 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vin_exploder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jake Mallory
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-07-18 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 2.11.1
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 2.11.1
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: simplecov
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: sequel
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: sqlite3
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: couchrest
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: activerecord
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - '>='
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: 3.0.0
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: 3.0.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: em-synchrony-couchdb
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.1.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.1.1
|
110
111
|
description: A caching client for vin decoding web services. The caching allows the
|
111
112
|
consumer to avoid the cost of secondary lookups.
|
112
113
|
email: tinomen@gmail.com
|
@@ -117,17 +118,18 @@ extra_rdoc_files:
|
|
117
118
|
- Gemfile.lock
|
118
119
|
- README.textile
|
119
120
|
files:
|
121
|
+
- lib/vin_exploder.rb
|
120
122
|
- lib/vin_exploder/abstract_adapter.rb
|
123
|
+
- lib/vin_exploder/cache.rb
|
121
124
|
- lib/vin_exploder/cache/active_record_cache_store.rb
|
122
125
|
- lib/vin_exploder/cache/couchrest_cache_store.rb
|
126
|
+
- lib/vin_exploder/cache/em_synchrony_couchdb_cache_store.rb
|
123
127
|
- lib/vin_exploder/cache/sequel_cache_store.rb
|
124
|
-
- lib/vin_exploder/cache.rb
|
125
128
|
- lib/vin_exploder/configuration.rb
|
126
129
|
- lib/vin_exploder/exploder.rb
|
127
130
|
- lib/vin_exploder/explosion.rb
|
128
131
|
- lib/vin_exploder/test_adapter.rb
|
129
132
|
- lib/vin_exploder/version.rb
|
130
|
-
- lib/vin_exploder.rb
|
131
133
|
- Gemfile
|
132
134
|
- Gemfile.lock
|
133
135
|
- README.textile
|
@@ -135,6 +137,7 @@ files:
|
|
135
137
|
- spec/cache/active_record_cache_store_spec.rb
|
136
138
|
- spec/cache/cache_store_spec.rb
|
137
139
|
- spec/cache/couchrest_cache_store_spec.rb
|
140
|
+
- spec/cache/em_synchrony_couchdb_cache_store_spec.rb
|
138
141
|
- spec/cache/sequel_cache_store_spec.rb
|
139
142
|
- spec/configuration_spec.rb
|
140
143
|
- spec/spec_helper.rb
|
@@ -142,6 +145,7 @@ files:
|
|
142
145
|
- spec/vin_exploder_spec.rb
|
143
146
|
homepage: http://github.com/tinomen/vin_exploder
|
144
147
|
licenses: []
|
148
|
+
metadata: {}
|
145
149
|
post_install_message:
|
146
150
|
rdoc_options:
|
147
151
|
- --title
|
@@ -153,23 +157,18 @@ rdoc_options:
|
|
153
157
|
require_paths:
|
154
158
|
- lib
|
155
159
|
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
-
none: false
|
157
160
|
requirements:
|
158
|
-
- -
|
161
|
+
- - '>='
|
159
162
|
- !ruby/object:Gem::Version
|
160
163
|
version: '0'
|
161
|
-
segments:
|
162
|
-
- 0
|
163
|
-
hash: -3012751816518866294
|
164
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
-
none: false
|
166
165
|
requirements:
|
167
|
-
- -
|
166
|
+
- - '>='
|
168
167
|
- !ruby/object:Gem::Version
|
169
168
|
version: 1.3.6
|
170
169
|
requirements: []
|
171
170
|
rubyforge_project:
|
172
|
-
rubygems_version:
|
171
|
+
rubygems_version: 2.0.3
|
173
172
|
signing_key:
|
174
173
|
specification_version: 3
|
175
174
|
summary: A caching client for vin decoding services
|
@@ -178,6 +177,7 @@ test_files:
|
|
178
177
|
- spec/cache/active_record_cache_store_spec.rb
|
179
178
|
- spec/cache/cache_store_spec.rb
|
180
179
|
- spec/cache/couchrest_cache_store_spec.rb
|
180
|
+
- spec/cache/em_synchrony_couchdb_cache_store_spec.rb
|
181
181
|
- spec/cache/sequel_cache_store_spec.rb
|
182
182
|
- spec/configuration_spec.rb
|
183
183
|
- spec/spec_helper.rb
|