Class: Derailleur::Context
- Inherits:
-
Object
- Object
- Derailleur::Context
- Defined in:
- lib/derailleur/base/context.rb
Overview
A context is the place where we handle an incoming HTTP Request. much like a Rack application, it has an env and the result must be an array of three items: [status, headers, content] The content is just an instance_evaluation of a callback passed during initialization.
Instance Attribute Summary collapse
-
#blk ⇒ Object
readonly
The block of code that will be instance_evaled to produce the HTTP response’s body.
-
#content ⇒ Object
The body of the HTTP response, must comply with Rack’s specification.
-
#ctx ⇒ Object
readonly
The Derailleur context.
-
#env ⇒ Object
readonly
The Rack environment.
-
#headers ⇒ Object
readonly
A hash representing the HTTP response’s headers.
-
#status ⇒ Object
The HTTP response’s status.
Instance Method Summary collapse
-
#app ⇒ Object
The Derailleur::Application for this context.
-
#evaluate! ⇒ Object
Simply instance_evaluates the block blk in the context of self.
-
#extname ⇒ Object
Returns the extension name of the HTTP path.
-
#initialize(env, ctx, &blk) ⇒ Context
constructor
A new instance of Context.
-
#params ⇒ Object
The parameters as parsed from the URL/HTTP-path chunks.
-
#result ⇒ Object
Method that wraps the status, headers and content into an array for Rack specification.
Constructor Details
#initialize(env, ctx, &blk) ⇒ Context
Returns a new instance of Context.
28 29 30 31 32 33 34 35 |
# File 'lib/derailleur/base/context.rb', line 28 def initialize(env, ctx, &blk) @status = 200 @env = env @ctx = ctx @blk = blk @content = nil @headers = {'Content-Type' => 'text/plain'} end |
Instance Attribute Details
#blk ⇒ Object (readonly)
The block of code that will be instance_evaled to produce the HTTP response’s body
26 27 28 |
# File 'lib/derailleur/base/context.rb', line 26 def blk @blk end |
#content ⇒ Object
The body of the HTTP response, must comply with Rack’s specification
22 23 24 |
# File 'lib/derailleur/base/context.rb', line 22 def content @content end |
#ctx ⇒ Object (readonly)
The Derailleur context
13 14 15 |
# File 'lib/derailleur/base/context.rb', line 13 def ctx @ctx end |
#env ⇒ Object (readonly)
The Rack environment
10 11 12 |
# File 'lib/derailleur/base/context.rb', line 10 def env @env end |
#headers ⇒ Object (readonly)
A hash representing the HTTP response’s headers
16 17 18 |
# File 'lib/derailleur/base/context.rb', line 16 def headers @headers end |
#status ⇒ Object
The HTTP response’s status
19 20 21 |
# File 'lib/derailleur/base/context.rb', line 19 def status @status end |
Instance Method Details
#app ⇒ Object
The Derailleur::Application for this context
43 44 45 |
# File 'lib/derailleur/base/context.rb', line 43 def app ctx['derailleur'] end |
#evaluate! ⇒ Object
Simply instance_evaluates the block blk in the context of self
38 39 40 |
# File 'lib/derailleur/base/context.rb', line 38 def evaluate! @content = instance_eval &blk end |
#extname ⇒ Object
Returns the extension name of the HTTP path
59 60 61 |
# File 'lib/derailleur/base/context.rb', line 59 def extname File.extname(env['PATH_INFO']) end |
#params ⇒ Object
The parameters as parsed from the URL/HTTP-path chunks
48 49 50 |
# File 'lib/derailleur/base/context.rb', line 48 def params ctx['derailleur.params'] end |
#result ⇒ Object
Method that wraps the status, headers and content into an array for Rack specification.
54 55 56 |
# File 'lib/derailleur/base/context.rb', line 54 def result [status, headers, content] end |