Module: Camping::Base
- Includes:
- Helpers
- Defined in:
- lib/camping.rb
Constant Summary collapse
- Z =
"\r\n"
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#cookies ⇒ Object
Returns the value of attribute cookies.
-
#env ⇒ Object
Returns the value of attribute env.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#input ⇒ Object
Returns the value of attribute input.
-
#root ⇒ Object
Returns the value of attribute root.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #initialize(r, e, m) ⇒ Object
- #method_missing(*a, &b) ⇒ Object
- #r(s, b, h = {}) ⇒ Object
- #redirect(*a) ⇒ Object
- #service(*a) ⇒ Object
- #to_s ⇒ Object
Methods included from Helpers
#/, #R, #URL, #errors_for
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*a, &b) ⇒ Object
9 10 11 |
# File 'lib/camping.rb', line 9 def method_missing*a,&b a.shift if a[0]==:render;m=Mab.new({},self);s=m.capture{send(*a,&b)};s=m.layout{s}if /^_/!~a[0].to_s and m.respond_to?:layout;s end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
8 9 10 |
# File 'lib/camping.rb', line 8 def body @body end |
#cookies ⇒ Object
Returns the value of attribute cookies.
8 9 10 |
# File 'lib/camping.rb', line 8 def @cookies end |
#env ⇒ Object
Returns the value of attribute env.
8 9 10 |
# File 'lib/camping.rb', line 8 def env @env end |
#headers ⇒ Object
Returns the value of attribute headers.
8 9 10 |
# File 'lib/camping.rb', line 8 def headers @headers end |
#input ⇒ Object
Returns the value of attribute input.
8 9 10 |
# File 'lib/camping.rb', line 8 def input @input end |
#root ⇒ Object
Returns the value of attribute root.
8 9 10 |
# File 'lib/camping.rb', line 8 def root @root end |
#status ⇒ Object
Returns the value of attribute status.
8 9 10 |
# File 'lib/camping.rb', line 8 def status @status end |
Instance Method Details
#initialize(r, e, m) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/camping.rb', line 13 def initialize r,e,m;e=H[e.to_hash];@status,@method,@env,@headers,@root=200,m. downcase,e,{'Content-Type'=>"text/html"},e.SCRIPT_NAME.sub(/\/$/,'') @k=C.kp e.HTTP_COOKIE;q=C.qs_parse e.QUERY_STRING;@in=r if%r|\Amultipart/form-.*boundary=\"?([^\";,]+)|n.match e.CONTENT_TYPE b=/(?:\r?\n|\A)#{Regexp::quote("--#$1")}(?:--)?\r$/;until@in.eof?;fh=H[];for l in@in 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;while l=@in.read(16384);if l=~b;o<<$`.chomp;@in.seek(-$'. size,IO::SEEK_CUR);break;end;o<<l;end;q[fn]=fh if fn;fh[:tempfile].rewind if fh.is_a?H;end;elsif@method=="post";q.u C.qs_parse(@in.read)end;@cookies,@input= @k.dup,q.dup end |
#r(s, b, h = {}) ⇒ Object
11 12 |
# File 'lib/camping.rb', line 11 def r s,b,h={};@status=s;@headers. merge!h;@body=b end |
#redirect(*a) ⇒ Object
12 |
# File 'lib/camping.rb', line 12 def redirect*a;r 302,'','Location'=>URL(*a)end |