class Puppet::Network::HTTP::Route

Constants

MethodNotAllowedHandler
NO_HANDLERS

Attributes

path_matcher[R]

Public Class Methods

new(path_matcher) click to toggle source
   # File lib/puppet/network/http/route.rb
14 def initialize(path_matcher)
15   @path_matcher = path_matcher
16   @method_handlers = {
17     :GET => NO_HANDLERS,
18     :HEAD => NO_HANDLERS,
19     :OPTIONS => NO_HANDLERS,
20     :POST => NO_HANDLERS,
21     :PUT => NO_HANDLERS,
22     :DELETE => NO_HANDLERS
23   }
24   @chained = []
25 end
path(path_matcher) click to toggle source
   # File lib/puppet/network/http/route.rb
10 def self.path(path_matcher)
11   new(path_matcher)
12 end

Public Instance Methods

any(*handlers) click to toggle source
   # File lib/puppet/network/http/route.rb
57 def any(*handlers)
58   @method_handlers.each do |method, registered_handlers|
59     @method_handlers[method] = handlers
60   end
61   return self
62 end
chain(*routes) click to toggle source
   # File lib/puppet/network/http/route.rb
64 def chain(*routes)
65   @chained = routes
66   self
67 end
delete(*handlers) click to toggle source
   # File lib/puppet/network/http/route.rb
52 def delete(*handlers)
53   @method_handlers[:DELETE] = handlers
54   return self
55 end
get(*handlers) click to toggle source
   # File lib/puppet/network/http/route.rb
27 def get(*handlers)
28   @method_handlers[:GET] = handlers
29   return self
30 end
head(*handlers) click to toggle source
   # File lib/puppet/network/http/route.rb
32 def head(*handlers)
33   @method_handlers[:HEAD] = handlers
34   return self
35 end
inspect() click to toggle source
   # File lib/puppet/network/http/route.rb
92 def inspect
93   "Route #{@path_matcher.inspect}"
94 end
matches?(request) click to toggle source
   # File lib/puppet/network/http/route.rb
69 def matches?(request)
70   Puppet.debug { "Evaluating match for #{self.inspect}" }
71   if match(request.routing_path)
72     return true
73   else
74     Puppet.debug { "Did not match path (#{request.routing_path.inspect})" }
75   end
76   return false
77 end
options(*handlers) click to toggle source
   # File lib/puppet/network/http/route.rb
37 def options(*handlers)
38   @method_handlers[:OPTIONS] = handlers
39   return self
40 end
post(*handlers) click to toggle source
   # File lib/puppet/network/http/route.rb
42 def post(*handlers)
43   @method_handlers[:POST] = handlers
44   return self
45 end
process(request, response) click to toggle source
   # File lib/puppet/network/http/route.rb
79 def process(request, response)
80   handlers = @method_handlers[request.method.upcase.intern] || NO_HANDLERS
81   handlers.each do |handler|
82     handler.call(request, response)
83   end
84 
85   subrequest = request.route_into(match(request.routing_path).to_s)
86   chained_route = @chained.find { |route| route.matches?(subrequest) }
87   if chained_route
88     chained_route.process(subrequest, response)
89   end
90 end
put(*handlers) click to toggle source
   # File lib/puppet/network/http/route.rb
47 def put(*handlers)
48   @method_handlers[:PUT] = handlers
49   return self
50 end

Private Instance Methods

match(path) click to toggle source
    # File lib/puppet/network/http/route.rb
 98 def match(path)
 99   @path_matcher.match(path)
100 end