Class: Syntropy::App

Inherits:
Object
  • Object
show all
Defined in:
lib/syntropy/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src_path, mount_path) ⇒ App

Returns a new instance of App.



12
13
14
15
16
17
18
# File 'lib/syntropy/app.rb', line 12

def initialize(src_path, mount_path)
  @src_path = src_path
  @mount_path = mount_path
  @route_cache = {}

  @relative_path_re = calculate_relative_path_re(mount_path)
end

Instance Attribute Details

#route_cacheObject (readonly)

Returns the value of attribute route_cache.



10
11
12
# File 'lib/syntropy/app.rb', line 10

def route_cache
  @route_cache
end

Instance Method Details

#call(req) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/syntropy/app.rb', line 31

def call(req)
  entry = find_route(req.path)
  render_entry(req, entry)
rescue StandardError => e
  p e
  p e.backtrace
  req.respond(e.message, ':status' => Qeweney::Status::INTERNAL_SERVER_ERROR)
end

#find_route(path, cache: true) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/syntropy/app.rb', line 20

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