class ApiValve::RouteSet
Constants
- METHODS
- Route
Public Class Methods
new()
click to toggle source
# File lib/api_valve/route_set.rb, line 15 def initialize reset_routes end
Public Instance Methods
any(path = nil, options = {}, &block)
click to toggle source
# File lib/api_valve/route_set.rb, line 59 def any(path = nil, options = {}, &block) append METHODS, path, options, &block end
delete(path = nil, options = {}, &block)
click to toggle source
# File lib/api_valve/route_set.rb, line 35 def delete(path = nil, options = {}, &block) push :delete, path, options, &block end
get(path = nil, options = {}, &block)
click to toggle source
# File lib/api_valve/route_set.rb, line 39 def get(path = nil, options = {}, &block) push :get, path, options, &block end
head(path = nil, options = {}, &block)
click to toggle source
# File lib/api_valve/route_set.rb, line 43 def head(path = nil, options = {}, &block) push :head, path, options, &block end
match(env)
click to toggle source
# File lib/api_valve/route_set.rb, line 19 def match(env) request = Rack::Request.new(env) # For security reasons do not allow URLs that could break out of the proxy namespace on the # server. Preferably an nxing/apache rewrite will kill these URLs before they hit us raise 'URL not supported' if request.path_info.include?('/../') match_data = nil route = @routes && @routes[request.request_method.downcase].find do |r| (match_data = r.match(request.path_info)) end raise Error::NotRouted, 'Endpoint not found' unless route [route, match_data] end
patch(path = nil, options = {}, &block)
click to toggle source
# File lib/api_valve/route_set.rb, line 47 def patch(path = nil, options = {}, &block) push :patch, path, options, &block end
post(path = nil, options = {}, &block)
click to toggle source
# File lib/api_valve/route_set.rb, line 51 def post(path = nil, options = {}, &block) push :post, path, options, &block end
push(methods, regexp, options = {}, &block)
click to toggle source
# File lib/api_valve/route_set.rb, line 63 def push(methods, regexp, options = {}, &block) add_route :push, methods, regexp, options, &block end
Also aliased as: append
put(path = nil, options = {}, &block)
click to toggle source
# File lib/api_valve/route_set.rb, line 55 def put(path = nil, options = {}, &block) push :put, path, options, &block end
reset_routes()
click to toggle source
# File lib/api_valve/route_set.rb, line 73 def reset_routes @routes = METHODS.map { |v| [v, []] }.to_h.with_indifferent_access.freeze end
unshift(methods, regexp = nil, options = {}, &block)
click to toggle source
# File lib/api_valve/route_set.rb, line 69 def unshift(methods, regexp = nil, options = {}, &block) add_route :unshift, methods, regexp, options, &block end
Private Instance Methods
add_route(how, methods, regexp, options, &block)
click to toggle source
# File lib/api_valve/route_set.rb, line 79 def add_route(how, methods, regexp, options, &block) methods = METHODS if methods.to_s == 'any' Array.wrap(methods).each do |method| @routes[method].public_send how, Route.new(regexp, options, block) end end