Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Some initial files added

  • Loading branch information...
commit 8ff9e8dd9e58263e19702022752b4c4794a6e560 1 parent 91ca6d1
@yrashk authored
View
28 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)
View
4 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'
View
7 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
View
56 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
Please sign in to comment.
Something went wrong with that request. Please try again.