Class: Syntropy::Router
- Inherits:
-
Object
- Object
- Syntropy::Router
- Defined in:
- lib/syntropy/router.rb
Instance Method Summary collapse
- #[](path) ⇒ Object
- #calc_route_proc_with_hooks(entry, proc) ⇒ Object
-
#initialize(opts, module_loader = nil) ⇒ Router
constructor
A new instance of Router.
- #start_file_watcher ⇒ Object
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.(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_watcher ⇒ Object
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 |