class Puppet::Network::HTTP::Route

Constants

MethodNotAllowedHandler
NO_HANDLERS

Attributes

path_matcher[R]

Public Instance Methods

any(*handlers) click to toggle source
# File lib/puppet/network/http/route.rb, line 57
def any(*handlers)
  @method_handlers.each do |method, registered_handlers|
    @method_handlers[method] = handlers
  end
  return self
end
chain(*routes) click to toggle source
# File lib/puppet/network/http/route.rb, line 64
def chain(*routes)
  @chained = routes
  self
end
delete(*handlers) click to toggle source
# File lib/puppet/network/http/route.rb, line 52
def delete(*handlers)
  @method_handlers[:DELETE] = handlers
  return self
end
get(*handlers) click to toggle source
# File lib/puppet/network/http/route.rb, line 27
def get(*handlers)
  @method_handlers[:GET] = handlers
  return self
end
head(*handlers) click to toggle source
# File lib/puppet/network/http/route.rb, line 32
def head(*handlers)
  @method_handlers[:HEAD] = handlers
  return self
end
inspect() click to toggle source
# File lib/puppet/network/http/route.rb, line 91
def inspect
  "Route #{@path_matcher.inspect}"
end
matches?(request) click to toggle source
# File lib/puppet/network/http/route.rb, line 69
def matches?(request)
  Puppet.debug("Evaluating match for #{self.inspect}")
  if match(request.routing_path)
    return true
  else
    Puppet.debug("Did not match path (#{request.routing_path.inspect})")
  end
  return false
end
options(*handlers) click to toggle source
# File lib/puppet/network/http/route.rb, line 37
def options(*handlers)
  @method_handlers[:OPTIONS] = handlers
  return self
end
post(*handlers) click to toggle source
# File lib/puppet/network/http/route.rb, line 42
def post(*handlers)
  @method_handlers[:POST] = handlers
  return self
end
process(request, response) click to toggle source
# File lib/puppet/network/http/route.rb, line 79
def process(request, response)
  handlers = @method_handlers[request.method.upcase.intern] || NO_HANDLERS
  handlers.each do |handler|
    handler.call(request, response)
  end

  subrequest = request.route_into(match(request.routing_path).to_s)
  if chained_route = @chained.find { |route| route.matches?(subrequest) }
    chained_route.process(subrequest, response)
  end
end
put(*handlers) click to toggle source
# File lib/puppet/network/http/route.rb, line 47
def put(*handlers)
  @method_handlers[:PUT] = handlers
  return self
end

Public Class Methods

new(path_matcher) click to toggle source
# File lib/puppet/network/http/route.rb, line 14
def initialize(path_matcher)
  @path_matcher = path_matcher
  @method_handlers = {
    :GET => NO_HANDLERS,
    :HEAD => NO_HANDLERS,
    :OPTIONS => NO_HANDLERS,
    :POST => NO_HANDLERS,
    :PUT => NO_HANDLERS,
    :DELETE => NO_HANDLERS
  }
  @chained = []
end
path(path_matcher) click to toggle source
# File lib/puppet/network/http/route.rb, line 10
def self.path(path_matcher)
  new(path_matcher)
end