class SoarSc::Rack::Router::Route
Constants
- EMPTY_HASH
- PARAMETER_PREFIX
- PARAMETER_VALID_REGEXP
- PATH_INFO
- REQUEST_METHOD
- SCRIPT_NAME
Attributes
action[R]
method[R]
path[R]
Public Class Methods
new(method, path, action)
click to toggle source
# File lib/soar_sc/rack/router/route.rb, line 22 def initialize(method, path, action) @method, @path, @action = method, path, action validate @static = components(@path).none? { |c| c.start_with?(PARAMETER_PREFIX) } end
Public Instance Methods
extract_path_parameters(env)
click to toggle source
# File lib/soar_sc/rack/router/route.rb, line 32 def extract_path_parameters(env) return EMPTY_HASH if @static req_components = components(request_path(env)) parameters = {} components(@path).each_with_index do |c, i| parameters[c[1..-1]] = req_components[i] if c.start_with?(PARAMETER_PREFIX) end parameters end
matches?(env)
click to toggle source
# File lib/soar_sc/rack/router/route.rb, line 28 def matches?(env) method_matches?(env[REQUEST_METHOD]) and path_matches?(request_path(env)) end
to_s()
click to toggle source
# File lib/soar_sc/rack/router/route.rb, line 43 def to_s "<#{@method.inspect} #{@path.inspect} #{@action.inspect}>" end
Private Instance Methods
components(path)
click to toggle source
# File lib/soar_sc/rack/router/route.rb, line 82 def components(path) path.split('/') end
method_matches?(method)
click to toggle source
# File lib/soar_sc/rack/router/route.rb, line 49 def method_matches?(method) @method == method or @method == HttpMethod::ANY end
parameterized_path_matches?(path)
click to toggle source
# File lib/soar_sc/rack/router/route.rb, line 65 def parameterized_path_matches?(path) route_components = components(@path) req_components = components(path) return false unless route_components.size == req_components.size route_components.each_with_index do |c, i| return false unless c.start_with?(PARAMETER_PREFIX) or c == req_components[i] end return true end
path_matches?(path)
click to toggle source
# File lib/soar_sc/rack/router/route.rb, line 53 def path_matches?(path) if @static static_path_matches?(path) else parameterized_path_matches?(path) end end
request_path(env)
click to toggle source
# File lib/soar_sc/rack/router/route.rb, line 78 def request_path(env) env[SCRIPT_NAME] + env[PATH_INFO] end
static_path_matches?(path)
click to toggle source
# File lib/soar_sc/rack/router/route.rb, line 61 def static_path_matches?(path) path == @path end