vin_exploder 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +18 -9
- data/lib/vin_exploder/cache/activerecord_cache_store.rb +4 -4
- data/lib/vin_exploder/cache/couchrest_cache_store.rb +42 -0
- data/lib/vin_exploder/explosion.rb +0 -10
- data/lib/vin_exploder/version.rb +1 -1
- data/lib/vin_exploder.rb +7 -4
- data/spec/cache/couchrest_cache_store_spec.rb +56 -0
- data/spec/cache/sequel_cache_store_spec.rb +4 -3
- metadata +18 -4
data/Gemfile.lock
CHANGED
@@ -1,30 +1,38 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vin_exploder (0.
|
4
|
+
vin_exploder (0.3.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activemodel (3.0.
|
10
|
-
activesupport (= 3.0.
|
9
|
+
activemodel (3.0.9)
|
10
|
+
activesupport (= 3.0.9)
|
11
11
|
builder (~> 2.1.2)
|
12
12
|
i18n (~> 0.5.0)
|
13
|
-
activerecord (3.0.
|
14
|
-
activemodel (= 3.0.
|
15
|
-
activesupport (= 3.0.
|
13
|
+
activerecord (3.0.9)
|
14
|
+
activemodel (= 3.0.9)
|
15
|
+
activesupport (= 3.0.9)
|
16
16
|
arel (~> 2.0.10)
|
17
17
|
tzinfo (~> 0.3.23)
|
18
|
-
activesupport (3.0.
|
18
|
+
activesupport (3.0.9)
|
19
19
|
arel (2.0.10)
|
20
20
|
builder (2.1.2)
|
21
|
+
couchrest (1.0.2)
|
22
|
+
json (~> 1.5.1)
|
23
|
+
mime-types (~> 1.15)
|
24
|
+
rest-client (~> 1.6.1)
|
21
25
|
diff-lcs (1.1.2)
|
22
26
|
i18n (0.5.0)
|
27
|
+
json (1.5.3)
|
28
|
+
mime-types (1.16)
|
29
|
+
rest-client (1.6.3)
|
30
|
+
mime-types (>= 1.16)
|
23
31
|
rspec (2.6.0)
|
24
32
|
rspec-core (~> 2.6.0)
|
25
33
|
rspec-expectations (~> 2.6.0)
|
26
34
|
rspec-mocks (~> 2.6.0)
|
27
|
-
rspec-core (2.6.
|
35
|
+
rspec-core (2.6.4)
|
28
36
|
rspec-expectations (2.6.0)
|
29
37
|
diff-lcs (~> 1.1.2)
|
30
38
|
rspec-mocks (2.6.0)
|
@@ -33,13 +41,14 @@ GEM
|
|
33
41
|
simplecov-html (~> 0.4.4)
|
34
42
|
simplecov-html (0.4.5)
|
35
43
|
sqlite3 (1.3.3)
|
36
|
-
tzinfo (0.3.
|
44
|
+
tzinfo (0.3.28)
|
37
45
|
|
38
46
|
PLATFORMS
|
39
47
|
ruby
|
40
48
|
|
41
49
|
DEPENDENCIES
|
42
50
|
activerecord (>= 3.0.0)
|
51
|
+
couchrest
|
43
52
|
rspec (>= 2.6.0)
|
44
53
|
sequel
|
45
54
|
simplecov
|
@@ -13,25 +13,25 @@ module Cache
|
|
13
13
|
|
14
14
|
def initialize(options = {})
|
15
15
|
super
|
16
|
-
@
|
16
|
+
@model_class = options[:model_class]
|
17
17
|
end
|
18
18
|
|
19
19
|
def read(vin)
|
20
20
|
key = make_vin_cache_key(vin)
|
21
|
-
obj = @
|
21
|
+
obj = @model_class.find_by_key(key)
|
22
22
|
obj.data unless obj.nil?
|
23
23
|
end
|
24
24
|
|
25
25
|
def write(vin, hash)
|
26
26
|
key = make_vin_cache_key(vin)
|
27
|
-
obj = @
|
27
|
+
obj = @model_class.new :key => key, :data => hash
|
28
28
|
obj.save
|
29
29
|
hash
|
30
30
|
end
|
31
31
|
|
32
32
|
def delete(vin)
|
33
33
|
key = make_vin_cache_key(vin)
|
34
|
-
obj = @
|
34
|
+
obj = @model_class.find_by_key(key)
|
35
35
|
deleted = obj.delete()
|
36
36
|
!deleted.nil?
|
37
37
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'couchrest'
|
2
|
+
|
3
|
+
module VinExploder
|
4
|
+
module Cache
|
5
|
+
|
6
|
+
# A VinExploder cache adapter using CouchDB for saving the decoded vin attributes.
|
7
|
+
#
|
8
|
+
# this store assumes there is 1 attribute in the document:
|
9
|
+
# - *data*: A hash of the decoded vin attributes
|
10
|
+
class CouchrestCacheStore < Store
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
super
|
14
|
+
srv = CouchRest.new options[:host]
|
15
|
+
@db = srv.database!(options[:db_name])
|
16
|
+
# vin_view = db.save_doc({"_id" => "_design/vins", :views => {:vins => {:map => 'function(doc){ if(doc.key){ emit(doc.key, doc.data) } }'}}}) unless db.get("_design/vins")
|
17
|
+
end
|
18
|
+
|
19
|
+
def read(vin)
|
20
|
+
key = make_vin_cache_key(vin)
|
21
|
+
result = @db.get(key)['data'] rescue nil
|
22
|
+
hash = {}
|
23
|
+
result.each{|k,v| hash[k.to_sym] = v} unless result.nil?
|
24
|
+
hash.empty? ? nil : hash
|
25
|
+
end
|
26
|
+
|
27
|
+
def write(vin, hash)
|
28
|
+
key = make_vin_cache_key(vin)
|
29
|
+
@db.save_doc({"_id" => key, :data => hash})
|
30
|
+
hash
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete(vin)
|
34
|
+
key = make_vin_cache_key(vin)
|
35
|
+
result = @db.delete_doc(@db.get(key))
|
36
|
+
!result.nil? && result['ok']
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -25,16 +25,6 @@ module VinExploder
|
|
25
25
|
end
|
26
26
|
alias :success? :valid?
|
27
27
|
|
28
|
-
# def _dump(level=-1)
|
29
|
-
# [@vin, @all.to_yaml].join('^')
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# def self._load(args)
|
33
|
-
# a = *args.split('^')
|
34
|
-
# hash = YAML.load(a[1])
|
35
|
-
# new(a[0], hash)
|
36
|
-
# end
|
37
|
-
|
38
28
|
end
|
39
29
|
|
40
30
|
end
|
data/lib/vin_exploder/version.rb
CHANGED
data/lib/vin_exploder.rb
CHANGED
@@ -2,10 +2,13 @@
|
|
2
2
|
module VinExploder
|
3
3
|
|
4
4
|
def self.explode(vin)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
@@exploder ||= nil
|
6
|
+
if @@exploder.nil?
|
7
|
+
cache = VinExploder.config.cache_store ? VinExploder.config.cache_store.new(VinExploder.config.cache_options) : nil
|
8
|
+
adapter = VinExploder.config.adapter.new(VinExploder.config.adapter_options)
|
9
|
+
end
|
10
|
+
@@exploder ||= Exploder.new(adapter, cache)
|
11
|
+
explosion = @@exploder.get(vin)
|
9
12
|
end
|
10
13
|
|
11
14
|
def self.config
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'vin_exploder/cache'
|
3
|
+
require 'vin_exploder/cache/couchrest_cache_store'
|
4
|
+
|
5
|
+
module VinExploder
|
6
|
+
module Cache
|
7
|
+
|
8
|
+
describe CouchrestCacheStore do
|
9
|
+
before(:each) do
|
10
|
+
db_config = {:host => 'http://127.0.0.1:5984', :db_name => 'vindecoder_test'}
|
11
|
+
srv = CouchRest.new db_config[:host]
|
12
|
+
@db = srv.database(db_config[:db_name])
|
13
|
+
@db.delete! if @db rescue nil
|
14
|
+
|
15
|
+
@store = CouchrestCacheStore.new(db_config)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should initialize" do
|
19
|
+
@store.class.should == CouchrestCacheStore
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should read and write a hash" do
|
23
|
+
vin = '3D7LU38C83G854645'
|
24
|
+
hash = @store.read(vin)
|
25
|
+
hash.should be_nil
|
26
|
+
@store.write(vin, {:vin => vin, :make => 'Ford'})
|
27
|
+
hash = @store.read(vin)
|
28
|
+
hash.should_not be_nil
|
29
|
+
hash[:make].should == 'Ford'
|
30
|
+
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
|
+
|
40
|
+
it "should delete a vin from the cache" do
|
41
|
+
hash = @store.read(:fake_vin_number)
|
42
|
+
hash.should be_nil
|
43
|
+
@store.write(:fake_vin_number, {:vin => 'fake_vin_number', :make => 'Ford'})
|
44
|
+
hash = @store.read(:fake_vin_number)
|
45
|
+
hash.should_not be_nil
|
46
|
+
hash[:make].should == 'Ford'
|
47
|
+
deleted = @store.delete(:fake_vin_number)
|
48
|
+
deleted.should == true
|
49
|
+
hash = @store.read(:fake_vin_number)
|
50
|
+
hash.should be_nil
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -27,10 +27,11 @@ describe SequelCacheStore do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should read and write a hash" do
|
30
|
-
|
30
|
+
vin = '3D7LU38C83G854645'
|
31
|
+
hash = @store.read(vin)
|
31
32
|
hash.should be_nil
|
32
|
-
@store.write(
|
33
|
-
hash = @store.read(
|
33
|
+
@store.write(vin, {:vin => vin, :make => 'Ford'})
|
34
|
+
hash = @store.read(vin)
|
34
35
|
hash.should_not be_nil
|
35
36
|
hash[:make].should == 'Ford'
|
36
37
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: vin_exploder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jake Mallory
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-24 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -57,16 +57,27 @@ dependencies:
|
|
57
57
|
type: :development
|
58
58
|
version_requirements: *id004
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
60
|
+
name: couchrest
|
61
61
|
prerelease: false
|
62
62
|
requirement: &id005 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
67
|
+
version: "0"
|
68
68
|
type: :development
|
69
69
|
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: activerecord
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 3.0.0
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id006
|
70
81
|
description: A caching client for vin decoding web services. The caching allows the consumer to avoid the cost of secondary lookups.
|
71
82
|
email: tinomen@gmail.com
|
72
83
|
executables: []
|
@@ -80,6 +91,7 @@ extra_rdoc_files:
|
|
80
91
|
files:
|
81
92
|
- lib/vin_exploder/abstract_adapter.rb
|
82
93
|
- lib/vin_exploder/cache/activerecord_cache_store.rb
|
94
|
+
- lib/vin_exploder/cache/couchrest_cache_store.rb
|
83
95
|
- lib/vin_exploder/cache/sequel_cache_store.rb
|
84
96
|
- lib/vin_exploder/cache.rb
|
85
97
|
- lib/vin_exploder/configuration.rb
|
@@ -93,6 +105,7 @@ files:
|
|
93
105
|
- spec/abstract_adapter_spec.rb
|
94
106
|
- spec/cache/activerecord_cache_store_spec.rb
|
95
107
|
- spec/cache/cache_store_spec.rb
|
108
|
+
- spec/cache/couchrest_cache_store_spec.rb
|
96
109
|
- spec/cache/sequel_cache_store_spec.rb
|
97
110
|
- spec/configuration_spec.rb
|
98
111
|
- spec/spec_helper.rb
|
@@ -133,6 +146,7 @@ test_files:
|
|
133
146
|
- spec/abstract_adapter_spec.rb
|
134
147
|
- spec/cache/activerecord_cache_store_spec.rb
|
135
148
|
- spec/cache/cache_store_spec.rb
|
149
|
+
- spec/cache/couchrest_cache_store_spec.rb
|
136
150
|
- spec/cache/sequel_cache_store_spec.rb
|
137
151
|
- spec/configuration_spec.rb
|
138
152
|
- spec/spec_helper.rb
|