Class: Synapse::App
- Inherits:
-
Object
- Object
- Synapse::App
- Defined in:
- lib/synapse/base.rb
Overview
See the synopsis section of README.txt for usage.
See the RackRouter project for the kinds of routes you can setup.
Variables of note:
@response
a hash with keys :body, :headers, :status_code, the 3 items all rack handlers are expected to set.
Body is a string, status code is an http status code integer, and headers is a hash that
should conform to rack's contract.
@env
The rack env passed into this apps #call method
@params
The params that the matching Rack::Router route set.
Instance Attribute Summary collapse
-
#env ⇒ Object
Returns the value of attribute env.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#params ⇒ Object
Returns the value of attribute params.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#action ⇒ Object
The name of the action method, determined by the Route that Rack::Router bound to the incoming request.
-
#as_rack_app ⇒ Object
Alias for #router.
-
#call(env) ⇒ Object
The rack #call method.
-
#initialize(opts = {}) ⇒ App
constructor
Options: :logger => where to log to.
-
#router ⇒ Object
the router for this Synapse::App.
-
#theres_no_action ⇒ Object
Overridable method that handles missing action that was defined by a route.
Constructor Details
#initialize(opts = {}) ⇒ App
Options:
:logger => where to log to.
Note this is not the same thing as the rack access log (although you
can pass that logger in if you want). Default: Logger.new(STDOUT)
28 29 30 |
# File 'lib/synapse/base.rb', line 28 def initialize(opts = {}) @logger = opts[:logger] || Logger.new(STDOUT) end |
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
22 23 24 |
# File 'lib/synapse/base.rb', line 22 def env @env end |
#logger ⇒ Object
Returns the value of attribute logger.
22 23 24 |
# File 'lib/synapse/base.rb', line 22 def logger @logger end |
#params ⇒ Object
Returns the value of attribute params.
22 23 24 |
# File 'lib/synapse/base.rb', line 22 def params @params end |
#response ⇒ Object
Returns the value of attribute response.
22 23 24 |
# File 'lib/synapse/base.rb', line 22 def response @response end |
Instance Method Details
#action ⇒ Object
The name of the action method, determined by the Route that Rack::Router bound to the incoming request
51 52 53 |
# File 'lib/synapse/base.rb', line 51 def action self.params[:action] end |
#as_rack_app ⇒ Object
Alias for #router
39 |
# File 'lib/synapse/base.rb', line 39 def as_rack_app; self.router; end |
#call(env) ⇒ Object
The rack #call method
42 43 44 |
# File 'lib/synapse/base.rb', line 42 def call(env) dup._call(env) # be thread-safe end |
#router ⇒ Object
the router for this Synapse::App. Subclasses are required to override this. (see README.txt for example usage)
34 35 36 |
# File 'lib/synapse/base.rb', line 34 def router raise "#{self.class} must implement a 'router' method that returns a Rack::Router" end |
#theres_no_action ⇒ Object
Overridable method that handles missing action that was defined by a route
56 57 58 59 |
# File 'lib/synapse/base.rb', line 56 def theres_no_action self.response[:body] = "Action '#{self.action}' not found in '#{self.class}'" self.response[:status_code] = 500 end |