Changeset 234
- Timestamp:
- 09/30/2007 16:41:53 (14 months ago)
- Location:
- trunk/lib
- Files:
-
- 2 modified
-
camping-unabridged.rb (modified) (7 diffs)
-
camping.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/camping-unabridged.rb
r233 r234 29 29 # in its <tt>examples/camping</tt> directory. 30 30 # 31 %w[ active_supportmarkaby tempfile uri].map { |l| require l }31 %w[markaby tempfile uri].map { |l| require l } 32 32 33 33 # == Camping … … 86 86 S = IO.read(__FILE__) rescue nil 87 87 P = "Cam\ping Problem!" 88 H = HashWithIndifferentAccess 89 # An object-like Hash, based on ActiveSupport's HashWithIndifferentAccess. 88 # An object-like Hash. 90 89 # All Camping query string and cookie variables are loaded as this. 91 90 # … … 110 109 # Use the <tt>@cookies</tt> variable in the same fashion to access cookie variables. 111 110 # Also, the <tt>@env</tt> variable is an H containing the HTTP headers and server info. 112 class H 111 class H < Hash 113 112 # Gets or sets keys in the hash. 114 113 # … … 118 117 # 119 118 def method_missing(m,*a) 120 m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m ]:super121 end 122 alias u regular_update119 m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super 120 end 121 alias u merge! 123 122 end 124 123 … … 370 369 fh.u H[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten] 371 370 when /^Content-Type: (.+?)(\r$|\Z)/m 372 fh [:type]= $1371 fh.type = $1 373 372 end 374 373 end 375 fn=fh [:name]376 o=if fh [:filename]377 o=fh [:tempfile]=Tempfile.new(:C)374 fn=fh.name 375 o=if fh.filename 376 o=fh.tempfile=Tempfile.new(:C) 378 377 o.binmode 379 378 else … … 393 392 end 394 393 C.qsp(fn,'&;',fh,q) if fn 395 fh [:tempfile].rewind if fh.is_a?H394 fh.tempfile.rewind if fh.is_a?H 396 395 end 397 396 when "application/x-www-form-urlencoded" … … 675 674 # #=> #<Blog::Controllers::Login @user=... > 676 675 # 677 # Blog.get(:Info, :env => { :HTTP_HOST=> 'wagon'})676 # Blog.get(:Info, :env => {'HTTP_HOST' => 'wagon'}) 678 677 # #=> #<Blog::Controllers::Info @env={'HTTP_HOST'=>'wagon'} ...> 679 678 # -
trunk/lib/camping.rb
r233 r234 1 %w[ active_supportmarkaby tempfile uri].map{|l|require l};module Camping;C=self2 S=IO.read(__FILE__)rescue nil;P="Cam\ping Problem!"; H=HashWithIndifferentAccess3 class H;def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m]:super4 end;alias u regular_update;end;module Helpers def R c,*g;p,h=/\(.+?\)/,g.1 %w[markaby tempfile uri].map{|l|require l};module Camping;C=self 2 S=IO.read(__FILE__)rescue nil;P="Cam\ping Problem!";class H<Hash 3 def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super 4 end;alias u merge!;end;module Helpers def R c,*g;p,h=/\(.+?\)/,g. 5 5 grep(Hash);(g-=h).inject(c.urls.find{|x|x.scan(p).size==g.size}.dup){|s,a|s. 6 6 sub p,C.escape((a[a.class.primary_key]rescue a))}+(h.any?? "?"+h[0]. … … 20 20 @in.eof?;fh=H[];for l in@in;case l;when Z;break;when/^Content-D.+?: form-data;/ 21 21 fh.u H[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten];when 22 /^Content-Type: (.+?)(\r$|\Z)/m;fh [:type]=$1;end;end;fn=fh[:name];o=if fh[23 :filename];o=fh[:tempfile]=Tempfile.new(:C);o.binmode;else;fh=""end;s=8192;k=''22 /^Content-Type: (.+?)(\r$|\Z)/m;fh.type=$1;end;end;fn=fh.name;o=if fh. 23 filename;o=fh.tempfile=Tempfile.new(:C);o.binmode;else;fh=""end;s=8192;k='' 24 24 l=@in.read(s*2);while l;if(k<<l)=~b;o<<$`.chomp;@in.seek(-$'.size,IO::SEEK_CUR) 25 break;end;o<<k.slice!(0...s);l=@in.read(s);end;C.qsp(fn,'&;',fh,q)if fn;fh [26 :tempfile].rewind if fh.is_a?H;end;when "application/x-www-form-urlencoded"25 break;end;o<<k.slice!(0...s);l=@in.read(s);end;C.qsp(fn,'&;',fh,q)if fn;fh. 26 tempfile.rewind if fh.is_a?H;end;when "application/x-www-form-urlencoded" 27 27 q.u C.qsp(@in.read)end;@cookies,@input=@k.dup,q.dup end 28 28 def service*a;@body=send(@method,*a)if respond_to?@method
