Permalink
Browse files

Simple file-based store (for testing)

  • Loading branch information...
1 parent 3116c26 commit 5dddc383555b6f96e257828bac9b6d643a791255 @ismasan committed Jul 7, 2011
Showing with 45 additions and 0 deletions.
  1. +5 −0 Rakefile
  2. +1 −0 lib/rack-oauth2_utils.rb
  3. +39 −0 lib/rack-oauth2_utils/test_store.rb
View
@@ -1,2 +1,7 @@
require 'bundler'
Bundler::GemHelper.install_tasks
+
+desc 'Load everything'
+task :console do
+ system "irb -I lib -r rack-oauth2_utils.rb"
+end
View
@@ -1,6 +1,7 @@
require 'rack'
require 'rack-oauth2_utils/middleware'
require 'rack-oauth2_utils/oauth_request'
+require 'rack-oauth2_utils/test_store'
module Rack
module OAuth2Utils
@@ -0,0 +1,39 @@
+require 'pstore'
+module Rack
+ module OAuth2Utils
+
+ # Test persistent store. Stores to FS using PStore
+ # Not meant for production!
+ #
+ class TestStore
+ def initialize(file_path = '.')
+ @store = PStore.new(file_path)
+ end
+
+ def []=(key, value)
+ @store.transaction do
+ @store[key] = value
+ end
+ end
+
+ def [](key)
+ @store.transaction do
+ @store[key]
+ end
+ end
+
+ def delete(key)
+ @store.transaction do
+ @store.delete(key)
+ end
+ end
+
+ def roots
+ @store.transaction do
+ @store.roots
+ end
+ end
+ end
+
+ end
+end

0 comments on commit 5dddc38

Please sign in to comment.