Class: Rad::Router::BasicRouter
- Includes:
- AbstractRouter
- Defined in:
- lib/rad/router/_basic_router.rb
Constant Summary collapse
- SKIP_DEFAULT =
[/^#{rad.http.url_root}\/(favicon|fs|packaged)/]
Instance Attribute Summary collapse
-
#redirect_routes ⇒ Object
Returns the value of attribute redirect_routes.
-
#skip_routes ⇒ Object
Returns the value of attribute skip_routes.
Instance Method Summary collapse
- #decode(path, params) ⇒ Object
- #encode(*a) ⇒ Object
-
#initialize ⇒ BasicRouter
constructor
A new instance of BasicRouter.
- #redirect(path_regexp, processor) ⇒ Object
- #skip(path_regexp) ⇒ Object
Constructor Details
#initialize ⇒ BasicRouter
Returns a new instance of BasicRouter.
9 10 11 12 |
# File 'lib/rad/router/_basic_router.rb', line 9 def initialize self.skip_routes = SKIP_DEFAULT.clone self.redirect_routes = [] end |
Instance Attribute Details
#redirect_routes ⇒ Object
Returns the value of attribute redirect_routes.
5 6 7 |
# File 'lib/rad/router/_basic_router.rb', line 5 def redirect_routes @redirect_routes end |
#skip_routes ⇒ Object
Returns the value of attribute skip_routes.
5 6 7 |
# File 'lib/rad/router/_basic_router.rb', line 5 def skip_routes @skip_routes end |
Instance Method Details
#decode(path, params) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rad/router/_basic_router.rb', line 28 def decode path, params # skip if skip_routes.any?{|path_regexp| path_regexp =~ path} logger.info "RAD skipping '#{path}'" throw :halt, true end # redirect if = redirect_routes.find{|path_regexp, processor| path_regexp =~ path} path_regexp, processor = target = if processor.is_a? String path.sub(path_regexp, processor) else processor.call path end response = workspace.response # content_type = Mime[params.format] response.set!( status: :redirect, # content_type: content_type, body: %(<html><body>You are being <a href="#{target.html_escape if target}">redirected</a>.</body></html>) ) response.headers['Location'] = target throw :halt, true end end |
#encode(*a) ⇒ Object
25 26 |
# File 'lib/rad/router/_basic_router.rb', line 25 def encode *a end |
#redirect(path_regexp, processor) ⇒ Object
19 20 21 22 23 |
# File 'lib/rad/router/_basic_router.rb', line 19 def redirect path_regexp, processor path_regexp.must_be.a Regexp processor.must_be.a String, Proc redirect_routes << [path_regexp, processor] unless redirect_routes.include? [path_regexp, processor] end |
#skip(path_regexp) ⇒ Object
14 15 16 17 |
# File 'lib/rad/router/_basic_router.rb', line 14 def skip path_regexp path_regexp.must_be.a Regexp skip_routes << path_regexp unless skip_routes.include? path_regexp end |