Created
May 7, 2010 16:37
-
-
Save joonyou/393690 to your computer and use it in GitHub Desktop.
camping
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
require "uri";require "rack";class Object;def meta_def m,&b;(class<URL(*a). | |
to_s;end;def r404 p;P%"#{p} not found"end;def r500 k,m,e;raise e;end;def r501 m | |
P%"#{m.upcase} not implemented"end;def to_a;@env['rack.session']=@state;r=Rack:: | |
Response.new(@body,@status,@headers);@cookies.each{|k,v|next if @old_cookies[ | |
k]==v;v={:value=>v,:path=>self/"/"} if String===v;r.set_cookie(k,v)};r.to_a;end | |
def initialize(env,m) r=@request=Rack::Request.new(@env=env);@root,@input, | |
@cookies,@state,@headers,@status,@method=r.script_name.sub(/\/$/,''),n(r.params | |
),H[@old_cookies = r.cookies],H[r.session],{},m=~/r(\d+)/?$1.to_i: 200,m end;def | |
n h;Hash===h ?h.inject(H[]){|m,(k,v)|m[k]=n(v);m}: h end;def service *a;r=catch( | |
:halt){send(@method,*a)};@body||=r;self;end;end;module Controllers;@r=[];class<< | |
self;def r;@r end;def R *u;r=@r;Class.new{meta_def(:urls){u};meta_def(:inherited | |
){|x|r<'(\d+)',"X"=>'([^/]+)', | |
"Index"=>'';def M;def M;end;constants.map{|c|k=const_get(c);k.send:include,C, | |
Base,Helpers,Models;@r=[k]+r if r-[k]==r;k.meta_def(:urls){ [ "/#{c.scan( | |
/.[^A-Z]*/).map(&N.method(:[]))*'/'}"]}if !k.respond_to?:urls}end end;I=R() | |
end;X=Controllers;class<<e).to_a;end;def method_missing m,c,*a;X.M;h=Hash===a[-1]? | |
a.pop: {};e=H[Rack::MockRequest.env_for('',h.delete(:env)||{})];k=X.const_get(c | |
).new(e,m.to_s);h.each{|i,v|k.send"#{i}=",v};k.service(*a);end;def use*a,&b;m=a. | |
shift.new(method(:call),*a,&b);meta_def(:call){|e|m.call(e)}end end;module Views | |
include X,Helpers end;module Models;autoload:Base, | |
'camping/ar';end;autoload:Mab,'camping/mab';C end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment