Class: Wurk::Web::Extension::Renderer
- Inherits:
-
Object
- Object
- Wurk::Web::Extension::Renderer
- Defined in:
- lib/wurk/web/extension.rb
Overview
Ties it together: finds a registered extension by name, captures its
routes once (registered(app)), matches the request, and renders.
Class Method Summary collapse
-
.asset_file(name, file) ⇒ Object
[absolute_path, cache_for_seconds]of an asset under the extension's asset_paths, or nil if the extension/file isn't found. -
.call(name:, method:, subpath:, env:, mount:, embed: true) ⇒ Array(Integer, Hash, String)
embed: true(the engine's ext/:name/* endpoint) rewrites links and redirects into the embed URL space;embed: false(the standalonerun Sidekiq::WebRack app, #204) leaves the extension's own route paths as the URL space, like upstream. -
.route?(method, path) ⇒ Boolean
Whether a registered extension answers this verb and path.
Class Method Details
.asset_file(name, file) ⇒ Object
[absolute_path, cache_for_seconds] of an asset under the
extension's asset_paths, or nil if the extension/file isn't found.
The expand_path prefix check rejects ../ traversal out of the dir.
304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/wurk/web/extension.rb', line 304 def asset_file(name, file) ext = registered_extension(name) return nil unless ext Array(ext[:asset_paths]).each do |dir| path = ::File.(::File.join(dir, file.to_s)) next unless path.start_with?("#{::File.(dir)}/") && ::File.file?(path) return [path, ext[:cache_for] || 86_400] end nil end |
.call(name:, method:, subpath:, env:, mount:, embed: true) ⇒ Array(Integer, Hash, String)
embed: true (the engine's ext/:name/* endpoint) rewrites links
and redirects into the embed URL space; embed: false (the
standalone run Sidekiq::Web Rack app, #204) leaves the
extension's own route paths as the URL space, like upstream.
The keywords are request facts (name/verb/path/env) plus URL-space
(mount/embed); bundling them would just rename the list.
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/wurk/web/extension.rb', line 271 def call(name:, method:, subpath:, env:, mount:, embed: true) ext = registered_extension(name) return nil unless ext require 'erb' require 'cgi' # Registration failures are cached and reported per request, without # serving any routes captured before the failure. captured_app(ext) if (registration_error = ext[:_registration_error]) ::Wurk.configuration.handle_exception(registration_error, context: 'web-extension-registration') return [500, html_headers, 'Extension render error (see server logs)'] end env['wurk.ext.subpath'] = subpath render(ext, env.merge('REQUEST_METHOD' => method.to_s.upcase, 'PATH_INFO' => subpath), { mount: mount, embed: }) end |
.route?(method, path) ⇒ Boolean
Whether a registered extension answers this verb and path. Pure routing: nothing runs, so it is safe ahead of the authorization gates.
293 294 295 296 297 298 299 |
# File 'lib/wurk/web/extension.rb', line 293 def route?(method, path) require 'cgi' ::Wurk::Web.config.extensions.any? do |ext| app = captured_app(ext) !ext[:_registration_error] && app.route?(method, path) end end |