Skip to content

Commit

Permalink
Some initial files added
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed May 1, 2008
1 parent 91ca6d1 commit 8ff9e8d
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
28 changes: 28 additions & 0 deletions examples/todo.rb
@@ -0,0 +1,28 @@
#! /usr/bin/env ruby
$:.unshift File.dirname(__FILE__) + "/../lib"
require 'zoid'

StrokeDB::Config.build :default => true, :base_path => 'todo.strokedb'

module Todo

nsurl 'http://strokedb.com/zoid/examples/todo'

Item = StrokeDB::Meta.new do
def done!
self.done = true
save!
end
end

List = StrokeDB::Meta.new do
has_many :items
end

APPLICATION = Zoid::Application.find_or_create(:name => "Todo", :nsurl => Todo.nsurl)

end

puts "Serving #{Todo::APPLICATION}"

Zoid.run(:mongrel, Todo::APPLICATION)
4 changes: 3 additions & 1 deletion lib/zoid.rb
@@ -1,3 +1,5 @@
$:.unshift File.expand_path(File.dirname(__FILE__))

require 'zoid/strokedb'
require 'zoid/strokedb'
require 'zoid/rack'
require 'zoid/application'
7 changes: 7 additions & 0 deletions lib/zoid/application.rb
@@ -0,0 +1,7 @@
module Zoid
nsurl "http://strokedb.com/zoid"
Application = StrokeDB::Meta.new do
validates_presence_of :name
validates_presence_of :nsurl
end
end
56 changes: 56 additions & 0 deletions lib/zoid/rack.rb
@@ -0,0 +1,56 @@
require 'rack'

module Rack #:nodoc:

class Request #:nodoc:
POST_TUNNEL_METHODS_ALLOWED = %w(PUT DELETE OPTIONS HEAD)

def request_method
if post_tunnel_method?
params['_method'].upcase
else
@env['REQUEST_METHOD']
end
end

private

def post_tunnel_method?
@env['REQUEST_METHOD'] == 'POST' && POST_TUNNEL_METHODS_ALLOWED.include?(self.POST.fetch('_method', '').upcase)
end
end


module Adapter
class Zoid

def initialize(app)
@app = app
end

def call(env)
[200,{"Content-Type" => "text/html"}, "Welcome to #{@app.name}!"]
end

end
end

end

module Zoid


def self.run(handler,app)
case handler.to_sym
when :mongrel
Rack::Handler::Mongrel.run(Rack::Adapter::Zoid.new(app), :Port => 7777) do |server|
trap(:INT) do
server.stop
end
end
else
raise ArgumentError, "Unknown Rack handler #{handler}"
end
end

end

0 comments on commit 8ff9e8d

Please sign in to comment.