2007/9/27, why the lucky stiff <[EMAIL PROTECTED]>:
> Well, case-sensitiveness would be a prob with 1.5 as well. Since
> @env.HTTP_HOST will work and @env.http_host will not.
True. So what do you think of the attached patch ? It removes roughly
50 octets to camping.rb and seems to work pretty well, except for apps
that used :symbols to access H members.
--
Cheers,
zimbatm
Index: lib/camping.rb
===================================================================
--- lib/camping.rb (revision 232)
+++ lib/camping.rb (working copy)
@@ -1,7 +1,7 @@
-%w[active_support markaby tempfile uri].map{|l|require l};module Camping;C=self
-S=IO.read(__FILE__)rescue nil;P="Cam\ping Problem!";H=HashWithIndifferentAccess
-class H;def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m]:super
-end;alias u regular_update;end;module Helpers def R c,*g;p,h=/\(.+?\)/,g.
+%w[markaby tempfile uri].map{|l|require l};module Camping;C=self
+S=IO.read(__FILE__)rescue nil;P="Cam\ping Problem!";class H<Hash;
+def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super
+end;alias u merge!;end;module Helpers def R c,*g;p,h=/\(.+?\)/,g.
grep(Hash);(g-=h).inject(c.urls.find{|x|x.scan(p).size==g.size}.dup){|s,a|s.
sub p,C.escape((a[a.class.primary_key]rescue a))}+(h.any?? "?"+h[0].
map{|x|x.map{|z|C.escape z}*"="}*"&": "")end;def /(p);p[/^\//[EMAIL PROTECTED]:p
@@ -17,11 +17,11 @@
match e.CONTENT_TYPE;b=/(?:\r?\n|\A)#{Regexp::quote"--#$1"}(?:--)?\r$/;until
@in.eof?;fh=H[];for l [EMAIL PROTECTED];case l;when Z;break;when/^Content-D.+?: form-data;/
fh.u H[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten];when
-/^Content-Type: (.+?)(\r$|\Z)/m;fh[:type]=$1;end;end;fn=fh[:name];o=if fh[
-:filename];o=fh[:tempfile]=Tempfile.new(:C);o.binmode;else;fh=""end;s=8192;k=''
+/^Content-Type: (.+?)(\r$|\Z)/m;fh.type=$1;end;end;fn=fh.name;o=if fh.
+filename;o=fh.tempfile=Tempfile.new(:C);o.binmode;else;fh=""end;s=8192;k=''
[EMAIL PROTECTED](s*2);while l;if(k<<l)=~b;o<<$`.chomp;@in.seek(-$'.size,IO::SEEK_CUR)
-break;end;o<<k.slice!(0...s);[EMAIL PROTECTED](s);end;C.qsp(fn,'&;',fh,q)if fn;fh[
-:tempfile].rewind if fh.is_a?H;end;[EMAIL PROTECTED]"post" && e.CONTENT_TYPE==
+break;end;o<<k.slice!(0...s);[EMAIL PROTECTED](s);end;C.qsp(fn,'&;',fh,q)if fn;fh.
+tempfile.rewind if fh.is_a?H;end;[EMAIL PROTECTED]"post" && e.CONTENT_TYPE==
"application/x-www-form-urlencoded";q.u C.qsp(@in.read)end;@cookies,@[EMAIL PROTECTED]
dup,q.dup end;def service*a;@body=send(@method,*a)if [EMAIL PROTECTED]
headers["Set-Cookie"]=cookies.map{|k,v|"#{k}=#{C.escape v}; path=#{self/'/'}"if
Index: lib/camping-unabridged.rb
===================================================================
--- lib/camping-unabridged.rb (revision 232)
+++ lib/camping-unabridged.rb (working copy)
@@ -28,7 +28,7 @@
# http://rubyforge.org/projects/mongrel Mongrel comes with examples
# in its <tt>examples/camping</tt> directory.
#
-%w[active_support markaby tempfile uri].map { |l| require l }
+%w[markaby tempfile uri].map { |l| require l }
# == Camping
#
@@ -85,8 +85,7 @@
C = self
S = IO.read(__FILE__) rescue nil
P = "Cam\ping Problem!"
- H = HashWithIndifferentAccess
- # An object-like Hash, based on ActiveSupport's HashWithIndifferentAccess.
+ # An object-like Hash.
# All Camping query string and cookie variables are loaded as this.
#
# To access the query string, for instance, use the <tt>@input</tt> variable.
@@ -109,7 +108,7 @@
#
# Use the <tt>@cookies</tt> variable in the same fashion to access cookie variables.
# Also, the <tt>@env</tt> variable is an H containing the HTTP headers and server info.
- class H
+ class H < Hash
# Gets or sets keys in the hash.
#
# @cookies.my_favorite = :macadamian
@@ -117,9 +116,9 @@
# => :macadamian
#
def method_missing(m,*a)
- m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m]:super
+ m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super
end
- alias u regular_update
+ alias u merge!
end
# Helpers contains methods available in your controllers and views. You may add
@@ -368,12 +367,12 @@
when /^Content-D.+?: form-data;/
fh.u H[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten]
when /^Content-Type: (.+?)(\r$|\Z)/m
- fh[:type] = $1
+ fh.type = $1
end
end
- fn=fh[:name]
- o=if fh[:filename]
- o=fh[:tempfile]=Tempfile.new(:C)
+ fn=fh.name
+ o=if fh.filename
+ o=fh.tempfile=Tempfile.new(:C)
o.binmode
else
fh=""
@@ -391,7 +390,7 @@
[EMAIL PROTECTED](s)
end
C.qsp(fn,'&;',fh,q) if fn
- fh[:tempfile].rewind if fh.is_a?H
+ fh.tempfile.rewind if fh.is_a?H
end
elsif @method == "post" and e.CONTENT_TYPE == "application/x-www-form-urlencoded"
q.u(C.qsp(@in.read))
@@ -673,7 +672,7 @@
# Blog.post(:Login, :input => {'username' => 'admin', 'password' => 'camping'})
# #=> #<Blog::Controllers::Login @user=... >
#
- # Blog.get(:Info, :env => {:HTTP_HOST => 'wagon'})
+ # Blog.get(:Info, :env => {'HTTP_HOST' => 'wagon'})
# #=> #<Blog::Controllers::Info @env={'HTTP_HOST'=>'wagon'} ...>
#
def method_missing(m, c, *a)
_______________________________________________
Camping-list mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/camping-list