Created
April 17, 2009 21:11
-
-
Save akdubya/97261 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pastiche' | |
require 'pastiche/serializer' | |
require 'restclient' | |
module Pastiche | |
class RESTStore | |
def initialize(uri, opts={}) | |
@uri = uri | |
end | |
def supports_expiration? | |
false | |
end | |
def supports_enumeration? | |
true | |
end | |
def [](key) | |
RestClient.get("#{@uri}/#{key}") | |
end | |
def []=(key, value) | |
RestClient.post("#{@uri}/#{key}", value) | |
end | |
def store(key, value, opts={}) | |
RestClient.post("#{@uri}/#{key}", value) | |
end | |
def key?(key) | |
return false unless key | |
RestClient.head("#{@uri}/#{key}") | |
end | |
end | |
end | |
Pastiche.setup(:test, | |
Pastiche::Chain.new do | |
use Pastiche::Serializer, :serialize => :json | |
mount Pastiche::RESTStore.new('http://0.0.0.0:5984/foo_test') | |
end | |
) | |
class RestyModel < Pastiche::Entity | |
use :properties, :finders | |
property :body, String | |
set_storage Pastiche.stores[:test] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment