Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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
#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']]}
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