Changeset 234

Show
Ignore:
Timestamp:
09/30/2007 16:41:53 (14 months ago)
Author:
zimbatm
Message:

ActiveSupport? dependency gone ! H is now simply inheriting from Hash.

Location:
trunk/lib
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/camping-unabridged.rb

    r233 r234  
    2929# in its <tt>examples/camping</tt> directory.  
    3030# 
    31 %w[active_support markaby tempfile uri].map { |l| require l } 
     31%w[markaby tempfile uri].map { |l| require l } 
    3232 
    3333# == Camping  
     
    8686  S = IO.read(__FILE__) rescue nil 
    8787  P = "Cam\ping Problem!" 
    88   H = HashWithIndifferentAccess 
    89   # An object-like Hash, based on ActiveSupport's HashWithIndifferentAccess. 
     88  # An object-like Hash. 
    9089  # All Camping query string and cookie variables are loaded as this. 
    9190  #  
     
    110109  # Use the <tt>@cookies</tt> variable in the same fashion to access cookie variables. 
    111110  # Also, the <tt>@env</tt> variable is an H containing the HTTP headers and server info. 
    112   class H 
     111  class H < Hash 
    113112    # Gets or sets keys in the hash. 
    114113    # 
     
    118117    # 
    119118    def method_missing(m,*a) 
    120         m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m]:super 
    121     end 
    122     alias u regular_update 
     119        m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super 
     120    end 
     121    alias u merge! 
    123122  end 
    124123 
     
    370369              fh.u H[*$'.scan(/(?:\s(\w+)="([^"]+)")/).flatten] 
    371370            when /^Content-Type: (.+?)(\r$|\Z)/m 
    372               fh[:type] = $1 
     371              fh.type = $1 
    373372            end 
    374373          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) 
    378377            o.binmode 
    379378          else 
     
    393392          end 
    394393          C.qsp(fn,'&;',fh,q) if fn 
    395           fh[:tempfile].rewind if fh.is_a?H 
     394          fh.tempfile.rewind if fh.is_a?H 
    396395        end 
    397396      when "application/x-www-form-urlencoded" 
     
    675674    #   #=> #<Blog::Controllers::Login @user=... > 
    676675    # 
    677     #   Blog.get(:Info, :env => {:HTTP_HOST => 'wagon'}) 
     676    #   Blog.get(:Info, :env => {'HTTP_HOST' => 'wagon'}) 
    678677    #   #=> #<Blog::Controllers::Info @env={'HTTP_HOST'=>'wagon'} ...> 
    679678    # 
  • trunk/lib/camping.rb

    r233 r234  
    1 %w[active_support markaby tempfile uri].map{|l|require l};module Camping;C=self 
    2 S=IO.read(__FILE__)rescue nil;P="Cam\ping Problem!";H=HashWithIndifferentAccess 
    3 class H;def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m]:super 
    4 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 
     2S=IO.read(__FILE__)rescue nil;P="Cam\ping Problem!";class H<Hash 
     3def method_missing m,*a;m.to_s=~/=$/?self[$`]=a[0]:a==[]?self[m.to_s]:super 
     4end;alias u merge!;end;module Helpers def R c,*g;p,h=/\(.+?\)/,g. 
    55grep(Hash);(g-=h).inject(c.urls.find{|x|x.scan(p).size==g.size}.dup){|s,a|s. 
    66sub p,C.escape((a[a.class.primary_key]rescue a))}+(h.any?? "?"+h[0]. 
     
    2020@in.eof?;fh=H[];for l in@in;case l;when Z;break;when/^Content-D.+?: form-data;/ 
    2121fh.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. 
     23filename;o=fh.tempfile=Tempfile.new(:C);o.binmode;else;fh=""end;s=8192;k='' 
    2424l=@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" 
     25break;end;o<<k.slice!(0...s);l=@in.read(s);end;C.qsp(fn,'&;',fh,q)if fn;fh. 
     26tempfile.rewind if fh.is_a?H;end;when "application/x-www-form-urlencoded" 
    2727q.u C.qsp(@in.read)end;@cookies,@input=@k.dup,q.dup end 
    2828def service*a;@body=send(@method,*a)if respond_to?@method