Class: Syntropy::Router
- Inherits:
-
Object
- Object
- Syntropy::Router
- Defined in:
- lib/syntropy/router.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
Instance Method Summary collapse
- #[](path) ⇒ 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.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/syntropy/router.rb', line 7 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 Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
5 6 7 |
# File 'lib/syntropy/router.rb', line 5 def cache @cache end |
Instance Method Details
#[](path) ⇒ Object
26 27 28 |
# File 'lib/syntropy/router.rb', line 26 def [](path) get_route_entry(path) end |
#start_file_watcher ⇒ Object
30 31 32 33 |
# File 'lib/syntropy/router.rb', line 30 def start_file_watcher @opts[:logger]&.call('Watching for file changes...', nil) @machine.spin { file_watcher_loop } end |