Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
$:.unshift File.expand_path(File.dirname(__FILE__)) | ||
|
||
require 'zoid/strokedb' | ||
require 'zoid/strokedb' | ||
require 'zoid/rack' | ||
require 'zoid/application' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |