Skip to content

Commit

Permalink
* lib/camping.rb: sometime in the recentlies, Rails' ActiveSupport a…
Browse files Browse the repository at this point in the history
…dded merge and update methods to their HashWithIndifferentAcces. now, i love this hack, but the merge and updates they added don't allow that vital proc attachment I use in the query parsing. as a result query parsing was broken. until it's fixed, i'm aliasing :regular_update (their alias of :update).

 * lib/camping-unabridged.rb: ditto.
  • Loading branch information
_why committed Apr 19, 2006
1 parent 370f220 commit d91e00f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/camping-unabridged.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def method_missing(m,*a)
raise NoMethodError, "#{m}"
end
end
alias_method :u, :regular_update
end

# Helpers contains methods available in your controllers and views. You may add
Expand Down Expand Up @@ -372,7 +373,7 @@ def initialize(r, e, m) #:nodoc:
qs[fn]=fh if fn
}
elsif @method == "post"
qs.merge!(C.qs_parse(@in.read))
qs.u(C.qs_parse(@in.read))
end
@cookies, @input = @k.dup, qs.dup
end
Expand Down Expand Up @@ -540,11 +541,11 @@ def un(s); s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){[$1.delete('%')].pack(
# #=> {'post' => {'id' => '1', 'user' => '_why'}}
#
def qs_parse(qs, d = '&;')
m = proc {|_,o,n|o.merge(n,&m)rescue([*o]<<n)}
m = proc {|_,o,n|o.u(n,&m)rescue([*o]<<n)}
(qs||'').
split(/[#{d}] */n).
inject(H[]) { |h,p| k, v=un(p).split('=',2)
h.merge(k.split(/[\]\[]+/).reverse.
h.u(k.split(/[\]\[]+/).reverse.
inject(v) { |x,i| H[i,x] },&m)
}
end
Expand Down
8 changes: 4 additions & 4 deletions lib/camping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Base;include Helpers;attr_accessor :input,:cookies,:env,:headers,:body,
: form-data;.*(?:\s#{x}="([^"]+)")/m};fn=fh[:name];if fh[:filename];fh[:type]=
$1 if h=~/^Content-Type: (.+?)(\r\n|\Z)/m;fh[:tempfile]=Tempfile.new(:C).
instance_eval{binmode;write v;rewind;self}else;fh=v end;q[fn]=fh if fn}elsif
@method=="post";q.merge! C.qs_parse(@in.read) end;@cookies,@input=
@method=="post";q.u C.qs_parse(@in.read) end;@cookies,@input=
@k.dup,q.dup end;def service *a;@body=send(@method,*a)if respond_to?@method
@headers["Set-Cookie"]=@cookies.map{|k,v|"#{k}=#{C.escape(v)}; path=#{self/"/"}\
" if v != @k[k]}.compact;self end;def to_s;"Status: #{@status}\n#{@headers.map{
Expand All @@ -35,9 +35,9 @@ module Base;include Helpers;attr_accessor :input,:cookies,:env,:headers,:body,
eval(S.gsub(/Camping/,m.to_s),TOPLEVEL_BINDING)end;def escape s;s.to_s.gsub(
/([^ a-zA-Z0-9_.-]+)/n){'%'+$1.unpack('H2'*$1.size).join('%').upcase}.tr ' ','+'
end;def un s;s.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n){[$1.delete('%'
)].pack('H*')} end;def qs_parse q,d='&;';m=proc{|_,o,n|o.merge(n,&m)rescue([*o
)].pack('H*')} end;def qs_parse q,d='&;';m=proc{|_,o,n|o.u(n,&m)rescue([*o
]<<n)};q.to_s.split(/[#{d}] */n).inject(H[]){|h,p|k,v=un(p).split('=',2)
h.merge k.split(/[\]\[]+/).reverse.inject(v){|x,i|H[i,x]},&m}end;def kp(s);c=
h.u k.split(/[\]\[]+/).reverse.inject(v){|x,i|H[i,x]},&m}end;def kp(s);c=
qs_parse(s,';,')end;def run r=$stdin,e=ENV;k,a=Controllers.D un("/#{e['PATH_INFO']
}".gsub(/\/+/,'/'));k.send:include,C,Base,Models;k.new(r,e,(m=e['REQUEST_METHOD'
]||"GET")).service *a;rescue=>x;Controllers::ServerError.new(r,e,'get').service(
Expand All @@ -47,4 +47,4 @@ module Base;include Helpers;attr_accessor :input,:cookies,:env,:headers,:body,
Views;def tag! *g,&b;h=g[-1];[:href,:action,:src].map{|a|(h[a]=self/h[a])rescue
0};super end end;H=HashWithIndifferentAccess;class H;def method_missing m,*a
if m.to_s=~/=$/;self[$`]=a[0];elsif a.empty?;self[m];else;raise NoMethodError,
"#{m}" end end end end
"#{m}" end end;alias_method:u,:regular_update;end end

0 comments on commit d91e00f

Please sign in to comment.