Sha256: c03de504010a22ba66917b8aedb671368d92b8cfca6710c2492afdbb321ef55a
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 KB
Contents
module Gretel module Trails class Store class << self # Save an encoded array to the store. It must return the trail key that # can later be used to retrieve the array from the store. def save(array) raise "#{name} must implement #save to be able to save trails." end # Retrieve an encoded array from the store based on the saved key. # It must return either the array, or nil if the key was not found. def retrieve(key) raise "#{name} must implement #retrieve to be able to retrieve trails." end # Deletes expired keys from the store. def delete_expired raise "#{name} doesn't support deleting expired keys." end # Gets the number of stored trail keys. def key_count raise "#{name} doesn't support counting trail keys." end # Deletes all stored trail keys. def delete_all_keys raise "#{name} doesn't support deleting all trail keys." end # Encode array of +links+ to unique trail key. def encode(links) arr = links.map { |link| [link.key, link.text, (link.text.html_safe? ? 1 : 0), link.url] } save(arr) end # Decode unique trail key to array of links. def decode(key) if arr = retrieve(key) arr.map { |key, text, html_safe, url| Link.new(key.to_sym, (html_safe == 1 ? text.html_safe : text), url) } else [] end end # Resets all changes made to the store. Used for testing. def reset! instance_variables.each { |var| remove_instance_variable var } end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gretel-trails-0.0.2 | lib/gretel/trails/stores/store.rb |