class SoarScRouting::BaseRouter
Attributes
route_meta[R]
Public Class Methods
new(route_meta)
click to toggle source
# File lib/soar_sc_routing/base_router.rb, line 7 def initialize(route_meta) @route_meta = route_meta end
Public Instance Methods
redirect_to(url, http_code = 302)
click to toggle source
# File lib/soar_sc_routing/base_router.rb, line 18 def redirect_to(url, http_code = 302) [http_code, {'Location' => url, 'Content-Type' => 'text/html', 'Content-Length' => '0'}, []] end
route(request)
click to toggle source
# File lib/soar_sc_routing/base_router.rb, line 11 def route(request) route_path(request) rescue => ex excepted(ex) end
Protected Instance Methods
excepted(ex)
click to toggle source
# File lib/soar_sc_routing/base_router.rb, line 28 def excepted(ex) raise NotImplementedError.new "Implement exception renderer: #{ex}" end
not_found()
click to toggle source
# File lib/soar_sc_routing/base_router.rb, line 24 def not_found raise NotImplementedError.new "Implement not found renderer" end
Private Instance Methods
debug(message, flow_identifier)
click to toggle source
# File lib/soar_sc_routing/base_router.rb, line 34 def debug(message, flow_identifier) auditing = SoarAspects::Aspects::auditing if auditing auditing.debug(message, flow_identifier) else $stderr.puts(message) end end
request_verb_matches_route_verb?(request,path_lexicon)
click to toggle source
# File lib/soar_sc_routing/base_router.rb, line 65 def request_verb_matches_route_verb?(request,path_lexicon) return false if path_lexicon.nil? or path_lexicon[request.path].nil? path_lexicon[request.path]['method'].include?(request.env['REQUEST_METHOD']) end
route_matched_path(request, path)
click to toggle source
# File lib/soar_sc_routing/base_router.rb, line 43 def route_matched_path(request, path) debug("#{@route_meta.name} matched #{path}",request.params['flow_identifier']) http_code, content_type, body = @route_meta.routing[path].call(request) debug("controller returned #{http_code}, #{content_type}", request.params['flow_identifier']) return [http_code, content_type, body] end
route_path(request)
click to toggle source
# File lib/soar_sc_routing/base_router.rb, line 50 def route_path(request) debug("#{@route_meta.name} attempting to match #{request.path}",request.params['flow_identifier']) @route_meta.routing.each do |path, block| matches = Regexp.new(path).match(request.path) if matches && request_verb_matches_route_verb?(request,@route_meta.lexicon) request.define_singleton_method(:regex_matches) { return matches.to_a } return route_matched_path(request, path) end end debug("no match to #{request.path} on router #{@route_meta.name}",request.params['flow_identifier']) not_found end