Class: VinExploder::Cache::SequelCacheStore
- Defined in:
- lib/vin_exploder/cache/sequel_cache_store.rb
Overview
A VinExploder cache adapter using Sequel for saving the decoded vin attributes.
this store assumes there are 2 columns on the table:
-
key: the first 8, 10th and 11th characters of the vin
-
data: A hash of the decoded vin attributes
Instance Attribute Summary
Attributes inherited from Store
Instance Method Summary collapse
- #delete(vin) ⇒ Object
-
#initialize(options = {}) ⇒ SequelCacheStore
constructor
A new instance of SequelCacheStore.
- #read(vin) ⇒ Object
- #write(vin, hash) ⇒ Object
Methods inherited from Store
Constructor Details
#initialize(options = {}) ⇒ SequelCacheStore
Returns a new instance of SequelCacheStore.
14 15 16 17 |
# File 'lib/vin_exploder/cache/sequel_cache_store.rb', line 14 def initialize( = {}) super @connection = Sequel.connect() end |
Instance Method Details
#delete(vin) ⇒ Object
31 32 33 34 35 |
# File 'lib/vin_exploder/cache/sequel_cache_store.rb', line 31 def delete(vin) key = make_vin_cache_key(vin) result = @connection[:vins].where(:key => key).delete result > 0 end |
#read(vin) ⇒ Object
19 20 21 22 23 |
# File 'lib/vin_exploder/cache/sequel_cache_store.rb', line 19 def read(vin) key = make_vin_cache_key(vin) data = @connection[:vins].where(:key => key).first Marshal.load(data[:data]) unless data.nil? end |
#write(vin, hash) ⇒ Object
25 26 27 28 29 |
# File 'lib/vin_exploder/cache/sequel_cache_store.rb', line 25 def write(vin, hash) key = make_vin_cache_key(vin) @connection[:vins].insert(:key => key, :data => Marshal.dump(hash)) hash end |