class Hurley::Test::Handler
Constants
- EMPTY_OR_SLASH
- URL_ATTRS
Attributes
callback[R]
request[R]
Public Class Methods
new(request, callback)
click to toggle source
# File lib/hurley/test.rb, line 62 def initialize(request, callback) @request = request @callback = callback @path_regex = %r{\A#{@request.url.path}(/|\z)} end
not_found(request)
click to toggle source
# File lib/hurley/test.rb, line 56 def self.not_found(request) Response.new(request, 404, Header.new) do |res| res.receive_body("no test handler") end end
Public Instance Methods
call(request)
click to toggle source
# File lib/hurley/test.rb, line 68 def call(request) @run = true status, header, body = @callback.call(request) Response.new(request, status, Header.new(header)) do |res| Array(body).each do |chunk| res.receive_body(chunk) end end end
matches?(request)
click to toggle source
# File lib/hurley/test.rb, line 78 def matches?(request) return false unless @request.verb == request.verb handler_url = @request.url request_url = request.url URL_ATTRS.each do |attr| value = handler_url.send(attr) return false if value && value != request_url.send(attr) end handler_url.query.subset_of?(request_url.query) && (handler_url.path =~ EMPTY_OR_SLASH || request_url.path =~ @path_regex) end
run?()
click to toggle source
# File lib/hurley/test.rb, line 93 def run? !!@run end