Class: Syntropy::App
- Inherits:
-
Object
- Object
- Syntropy::App
- Defined in:
- lib/syntropy/app.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#module_loader ⇒ Object
readonly
Returns the value of attribute module_loader.
-
#mount_path ⇒ Object
readonly
Returns the value of attribute mount_path.
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
-
#routing_tree ⇒ Object
readonly
Returns the value of attribute routing_tree.
Class Method Summary collapse
Instance Method Summary collapse
-
#call(req) ⇒ void
Processes an incoming HTTP request.
-
#initialize(**env) ⇒ App
constructor
A new instance of App.
Constructor Details
#initialize(**env) ⇒ App
Returns a new instance of App.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/syntropy/app.rb', line 41 def initialize(**env) @machine = env[:machine] @root_dir = File.(env[:root_dir]) @mount_path = env[:mount_path] @env = env @module_loader = Syntropy::ModuleLoader.new(app: self, **env) setup_routing_tree start end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
39 40 41 |
# File 'lib/syntropy/app.rb', line 39 def env @env end |
#module_loader ⇒ Object (readonly)
Returns the value of attribute module_loader.
39 40 41 |
# File 'lib/syntropy/app.rb', line 39 def module_loader @module_loader end |
#mount_path ⇒ Object (readonly)
Returns the value of attribute mount_path.
39 40 41 |
# File 'lib/syntropy/app.rb', line 39 def mount_path @mount_path end |
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
39 40 41 |
# File 'lib/syntropy/app.rb', line 39 def root_dir @root_dir end |
#routing_tree ⇒ Object (readonly)
Returns the value of attribute routing_tree.
39 40 41 |
# File 'lib/syntropy/app.rb', line 39 def routing_tree @routing_tree end |
Class Method Details
.load(env) ⇒ Object
18 19 20 |
# File 'lib/syntropy/app.rb', line 18 def load(env) site_file_app(env) || default_app(env) end |
Instance Method Details
#call(req) ⇒ void
This method returns an undefined value.
Processes an incoming HTTP request. Requests are processed by first looking up the route for the request path, then calling the route proc. If the route proc is not set, it is computed according to the route target, and composed recursively into hooks encountered up the routing tree.
Normal exceptions (StandardError and descendants) are trapped and passed to route’s error handler. If no such handler is found, the default error handler is used, which simply generates a textual response containing the error message, and with the appropriate HTTP status code, according to the type of error.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/syntropy/app.rb', line 65 def call(req) route = @router_proc.(req.path, req.route_params) raise Syntropy::Error.not_found('Not found') if !route req.route = route proc = route[:proc] ||= compute_route_proc(route) proc.(req) rescue StandardError => e @env[:logger]&.error( message: "Error while serving request", method: req.method, path: req.path ) error_handler = get_error_handler(route) error_handler.(req, e) end |