Class: Syntropy::App
- Inherits:
-
Object
- Object
- Syntropy::App
- Defined in:
- lib/syntropy/app.rb
Instance Attribute Summary collapse
-
#route_cache ⇒ Object
readonly
Returns the value of attribute route_cache.
Instance Method Summary collapse
- #call(req) ⇒ Object
- #find_route(path, cache: true) ⇒ Object
-
#initialize(machine, src_path, mount_path, opts = {}) ⇒ App
constructor
A new instance of App.
Constructor Details
#initialize(machine, src_path, mount_path, opts = {}) ⇒ App
Returns a new instance of App.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/syntropy/app.rb', line 15 def initialize(machine, src_path, mount_path, opts = {}) @machine = machine @src_path = File.(src_path) @mount_path = mount_path @route_cache = {} @opts = opts @relative_path_re = calculate_relative_path_re(mount_path) @machine.spin do # we do startup stuff asynchronously, in order to first let TP2 do its # setup tasks @machine.sleep 0.25 @opts[:logger]&.call("Serving from #{File.(@src_path)}") start_file_watcher if opts[:watch_files] end end |
Instance Attribute Details
#route_cache ⇒ Object (readonly)
Returns the value of attribute route_cache.
13 14 15 |
# File 'lib/syntropy/app.rb', line 13 def route_cache @route_cache end |
Instance Method Details
#call(req) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/syntropy/app.rb', line 43 def call(req) entry = find_route(req.path) render_entry(req, entry) rescue StandardError => e p e p e.backtrace req.respond(e., ':status' => Qeweney::Status::INTERNAL_SERVER_ERROR) end |
#find_route(path, cache: true) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/syntropy/app.rb', line 32 def find_route(path, cache: true) cached = @route_cache[path] return cached if cached entry = calculate_route(path) if entry[:kind] != :not_found @route_cache[path] = entry if cache end entry end |