Class: Tap::Server
- Inherits:
-
Object
- Object
- Tap::Server
- Includes:
- Runner
- Defined in:
- lib/tap/server.rb,
lib/tap/server/data.rb,
lib/tap/server/runner.rb,
lib/tap/server/server_error.rb
Overview
::configurable
Defined Under Namespace
Modules: Runner Classes: Data, ServerError
Instance Attribute Summary collapse
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#thread ⇒ Object
Returns the value of attribute thread.
Attributes included from Runner
Instance Method Summary collapse
-
#admin?(input) ⇒ Boolean
Returns true if input is equal to the secret, if a secret is set.
-
#call(rack_env) ⇒ Object
The Rack interface method.
-
#initialize(controller = nil, config = {}) ⇒ Server
constructor
A new instance of Server.
- #route(rack_env) ⇒ Object
- #run! ⇒ Object
Methods included from Runner
Constructor Details
#initialize(controller = nil, config = {}) ⇒ Server
Returns a new instance of Server.
31 32 33 34 35 |
# File 'lib/tap/server.rb', line 31 def initialize(controller=nil, config={}) @controller = controller @thread = nil super(config) end |
Instance Attribute Details
#controller ⇒ Object
Returns the value of attribute controller.
27 28 29 |
# File 'lib/tap/server.rb', line 27 def controller @controller end |
#thread ⇒ Object
Returns the value of attribute thread.
29 30 31 |
# File 'lib/tap/server.rb', line 29 def thread @thread end |
Instance Method Details
#admin?(input) ⇒ Boolean
Returns true if input is equal to the secret, if a secret is set. Used to test if a particular request has rights to a remote administrative action.
40 41 42 |
# File 'lib/tap/server.rb', line 40 def admin?(input) secret != nil && input == secret end |
#call(rack_env) ⇒ Object
The Rack interface method.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tap/server.rb', line 66 def call(rack_env) # handle the request rack_env['tap.server'] = self unless controller = route(rack_env) raise ServerError.new("404 Error: could not route to controller", 404) end controller.call(rack_env) rescue ServerError $!.response rescue Exception ServerError.response($!) end |
#route(rack_env) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tap/server.rb', line 44 def route(rack_env) return controller unless router # route to a controller blank, path, path_info = rack_env['PATH_INFO'].split("/", 3) controller = lookup_controller(unescape(path)) if controller # adjust rack_env if route routes to a controller rack_env['SCRIPT_NAME'] = ["#{rack_env['SCRIPT_NAME'].chomp('/')}/#{path}"] rack_env['PATH_INFO'] = ["/#{path_info}"] else # use default controller controller = self.controller path = nil end rack_env['tap.controller_path'] = path controller end |
#run! ⇒ Object
81 82 83 |
# File 'lib/tap/server.rb', line 81 def run! super(self) end |