From becd26b0bdf44b3625caaa7643914d0379a4fea5 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 29 Aug 2016 10:26:54 +0200 Subject: refactor: let handlers check if they are applicable Instead of testing the preconditions for each handler in the dispatcher the dispatcher hands a request to one handler after the other until one of them responds. This is similar to the Chain of Responsibility patter but we iterate over the 'handler_chain' array instead of a linked list. To change the order of handlers or add other handlers change the array in the handler_chain function. --- lib/nickserver/request_handlers/fingerprint_handler.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/nickserver/request_handlers/fingerprint_handler.rb') diff --git a/lib/nickserver/request_handlers/fingerprint_handler.rb b/lib/nickserver/request_handlers/fingerprint_handler.rb index 3202c41..3c04fcd 100644 --- a/lib/nickserver/request_handlers/fingerprint_handler.rb +++ b/lib/nickserver/request_handlers/fingerprint_handler.rb @@ -6,6 +6,13 @@ module Nickserver class FingerprintHandler def call(request) + return unless request.fingerprint + handle_request(request) + end + + protected + + def handle_request(request) fingerprint = request.fingerprint if fingerprint.length == 40 && !fingerprint[/\H/] source = Nickserver::Hkp::Source.new -- cgit v1.2.3