Skip to content

Instantly share code, notes, and snippets.

@akdubya
Created April 17, 2009 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akdubya/97261 to your computer and use it in GitHub Desktop.
Save akdubya/97261 to your computer and use it in GitHub Desktop.
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