summaryrefslogtreecommitdiff
path: root/lib/nickserver/request_handlers/email_handler.rb
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-08-29 10:26:54 +0200
committerAzul <azul@riseup.net>2016-08-29 10:34:17 +0200
commitbecd26b0bdf44b3625caaa7643914d0379a4fea5 (patch)
tree8f6e5ddf548ce9262a7cabac76ed2f4e3873be22 /lib/nickserver/request_handlers/email_handler.rb
parent58d687f927aabc8aa2fdfc46132cb71706bdde46 (diff)
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.
Diffstat (limited to 'lib/nickserver/request_handlers/email_handler.rb')
-rw-r--r--lib/nickserver/request_handlers/email_handler.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/nickserver/request_handlers/email_handler.rb b/lib/nickserver/request_handlers/email_handler.rb
index 3f7515d..b163b27 100644
--- a/lib/nickserver/request_handlers/email_handler.rb
+++ b/lib/nickserver/request_handlers/email_handler.rb
@@ -8,6 +8,13 @@ module Nickserver
class EmailHandler
def call(request)
+ return unless request.email
+ handle_request(request)
+ end
+
+ protected
+
+ def handle_request(request)
email = EmailAddress.new(request.email)
if email.invalid?
ErrorResponse.new("Not a valid address")
@@ -16,8 +23,6 @@ module Nickserver
end
end
- protected
-
def send_key(email, request)
if local_address?(email, request)
source = Nickserver::CouchDB::Source.new