Skip to content

Instantly share code, notes, and snippets.

@saimonmoore
Created March 13, 2009 00:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saimonmoore/78368 to your computer and use it in GitHub Desktop.
Save saimonmoore/78368 to your computer and use it in GitHub Desktop.
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