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, env = {}) ⇒ App
constructor
A new instance of App.
- #invalidate_cache(fn) ⇒ Object
Constructor Details
#initialize(machine, src_path, mount_path, env = {}) ⇒ App
Returns a new instance of App.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/syntropy/app.rb', line 15 def initialize(machine, src_path, mount_path, env = {}) @machine = machine @src_path = src_path @mount_path = mount_path @route_cache = {} @env = env @relative_path_re = calculate_relative_path_re(mount_path) if (wf = env[:watch_files]) period = wf.is_a?(Numeric) ? wf : 0.1 machine.spin do Syntropy.file_watch(@machine, src_path, period: period) { invalidate_cache(it) } rescue Exception => e p e p e.backtrace end 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
54 55 56 57 58 59 60 61 |
# File 'lib/syntropy/app.rb', line 54 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
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/syntropy/app.rb', line 34 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 |
#invalidate_cache(fn) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/syntropy/app.rb', line 45 def invalidate_cache(fn) invalidated_keys = [] @route_cache.each do |k, v| invalidated_keys << k if v[:fn] == fn end invalidated_keys.each { @route_cache.delete(it) } end |