Class: Syntropy::Router

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

Instance Method Summary collapse

Constructor Details

#initialize(opts, module_loader = nil) ⇒ Router

Returns a new instance of Router.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/syntropy/router.rb', line 5

def initialize(opts, module_loader = nil)
  raise 'Invalid location given' if !File.directory?(opts[:location])

  @opts = opts
  @machine = opts[:machine]
  @root = File.expand_path(opts[:location])
  @mount_path = opts[:mount_path] || '/'
  @rel_path_re ||= /^#{@root}/
  @module_loader = module_loader

  @cache        = {} # maps url path to route entry
  @routes       = {} # maps canonical path to route entry (actual routes)
  @files        = {} # maps filename to entry
  @deps         = {} # maps filenames to array of dependent entries
  @x  = {} # maps directories to hook chains

  scan_routes
end

Instance Method Details

#[](path) ⇒ Object



24
25
26
# File 'lib/syntropy/router.rb', line 24

def [](path)
  get_route_entry(path)
end

#calc_route_proc_with_hooks(entry, proc) ⇒ Object



35
36
37
# File 'lib/syntropy/router.rb', line 35

def calc_route_proc_with_hooks(entry, proc)
  compose_up_tree_hooks(entry[:fn], proc)
end

#start_file_watcherObject



28
29
30
31
32
33
# File 'lib/syntropy/router.rb', line 28

def start_file_watcher
  @opts[:logger]&.info(
    message: 'Watching for file changes...'
  )
  @machine.spin { file_watcher_loop }
end