Sha256: f415ee1220016cbdf988b828ea46ceec7b0f00d659901549a422983d58af125a
Contents?: true
Size: 952 Bytes
Versions: 3
Compression:
Stored size: 952 Bytes
Contents
require 'active_record' require 'base64' module VinExploder module Cache # A VinExploder cache adapter using ActiveRecord for saving the decoded vin attributes. # # this store assumes a model with 2 attributes: # - *key*: the first 8, 10th and 11th characters of the vin # - *data*: A hash of the decoded vin attributes class ActiveRecordCacheStore < Store def initialize(options = {}) super @model_class = options[:model_class] end def read(vin) key = make_vin_cache_key(vin) obj = @model_class.find_by_key(key) obj.data unless obj.nil? end def write(vin, hash) key = make_vin_cache_key(vin) obj = @model_class.new :key => key, :data => hash obj.save hash end def delete(vin) key = make_vin_cache_key(vin) obj = @model_class.find_by_key(key) deleted = obj.delete() !deleted.nil? end end end end
Version data entries
3 entries across 3 versions & 1 rubygems