Class: ApiValve::RouteSet
- Inherits:
-
Object
- Object
- ApiValve::RouteSet
- Defined in:
- lib/api_valve/route_set.rb
Defined Under Namespace
Classes: Route
Constant Summary collapse
- METHODS =
%i(get post put patch delete head).freeze
Instance Method Summary collapse
- #any(path = nil, options = {}, prok = nil) ⇒ Object
- #delete(path = nil, options = {}, prok = nil) ⇒ Object
- #get(path = nil, options = {}, prok = nil) ⇒ Object
- #head(path = nil, options = {}, prok = nil) ⇒ Object
-
#initialize ⇒ RouteSet
constructor
A new instance of RouteSet.
- #match(env) ⇒ Object
- #patch(path = nil, options = {}, prok = nil) ⇒ Object
- #post(path = nil, options = {}, prok = nil) ⇒ Object
- #push(methods, regexp, options = {}, prok = nil) ⇒ Object (also: #append)
- #put(path = nil, options = {}, prok = nil) ⇒ Object
- #reset_routes ⇒ Object
- #unshift(methods, regexp = nil, options = {}, prok = nil) ⇒ Object
Constructor Details
#initialize ⇒ RouteSet
Returns a new instance of RouteSet.
15 16 17 |
# File 'lib/api_valve/route_set.rb', line 15 def initialize reset_routes end |
Instance Method Details
#any(path = nil, options = {}, prok = nil) ⇒ Object
59 60 61 |
# File 'lib/api_valve/route_set.rb', line 59 def any(path = nil, = {}, prok = nil) append METHODS, path, , prok || Proc.new end |
#delete(path = nil, options = {}, prok = nil) ⇒ Object
35 36 37 |
# File 'lib/api_valve/route_set.rb', line 35 def delete(path = nil, = {}, prok = nil) push :delete, path, , prok || Proc.new end |
#get(path = nil, options = {}, prok = nil) ⇒ Object
39 40 41 |
# File 'lib/api_valve/route_set.rb', line 39 def get(path = nil, = {}, prok = nil) push :get, path, , prok || Proc.new end |
#head(path = nil, options = {}, prok = nil) ⇒ Object
43 44 45 |
# File 'lib/api_valve/route_set.rb', line 43 def head(path = nil, = {}, prok = nil) push :head, path, , prok || Proc.new end |
#match(env) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 = {}, prok = nil) ⇒ Object
47 48 49 |
# File 'lib/api_valve/route_set.rb', line 47 def patch(path = nil, = {}, prok = nil) push :patch, path, , prok || Proc.new end |
#post(path = nil, options = {}, prok = nil) ⇒ Object
51 52 53 |
# File 'lib/api_valve/route_set.rb', line 51 def post(path = nil, = {}, prok = nil) push :post, path, , prok || Proc.new end |
#push(methods, regexp, options = {}, prok = nil) ⇒ Object Also known as: append
63 64 65 |
# File 'lib/api_valve/route_set.rb', line 63 def push(methods, regexp, = {}, prok = nil) add_route :push, methods, regexp, , prok || Proc.new end |
#put(path = nil, options = {}, prok = nil) ⇒ Object
55 56 57 |
# File 'lib/api_valve/route_set.rb', line 55 def put(path = nil, = {}, prok = nil) push :put, path, , prok || Proc.new end |
#reset_routes ⇒ Object
73 74 75 |
# File 'lib/api_valve/route_set.rb', line 73 def reset_routes @routes = Hash[METHODS.map { |v| [v, []] }].with_indifferent_access.freeze end |
#unshift(methods, regexp = nil, options = {}, prok = nil) ⇒ Object
69 70 71 |
# File 'lib/api_valve/route_set.rb', line 69 def unshift(methods, regexp = nil, = {}, prok = nil) add_route :unshift, methods, regexp, , prok || Proc.new end |