Created
March 13, 2009 00:13
-
-
Save saimonmoore/78368 to your computer and use it in GitHub Desktop.
This file contains 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
module CloudKit | |
if defined? ::BasicObject | |
class BasicObject < ::BasicObject | |
undef_method :== | |
undef_method :equal? | |
# Let ActiveSupport::BasicObject at least raise exceptions. | |
def raise(*args) | |
::Object.send(:raise, *args) | |
end | |
end | |
else | |
require 'blankslate' | |
BasicObject = BlankSlate | |
end | |
end |
This file contains 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
#config.ru | |
require 'cloudkit' | |
require 'rufus/tokyo' | |
$:.unshift File.expand_path(File.dirname(__FILE__)) + '/lib' | |
require 'rewindable_input' #<=== ensure rack input is rewindable | |
CloudKit.setup_storage_adapter(Rufus::Tokyo::Table.new('cloudkit.tdb')) | |
use Rack::Session::Pool | |
use CloudKit::RewindableInput | |
use CloudKit::Service, :collections => [:votes] | |
run lambda {|env| [200, {'Content-Type' => 'text/html', 'Content-Length' => '5'}, ['HELLO']]} |
This file contains 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 'basic_object' | |
module CloudKit | |
class RewindableInput | |
class RewindableIO < CloudKit::BasicObject | |
def initialize(io) | |
@io = io | |
@rewindable = io.is_a?(::StringIO) | |
end | |
def method_missing(method, *args, &block) | |
unless @rewindable | |
@io = ::StringIO.new(@io.read) | |
@rewindable = true | |
end | |
@io.__send__(method, *args, &block) | |
end | |
end | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
env['rack.input'] = RewindableIO.new(env['rack.input']) | |
@app.call(env) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment