diff options
author | Azul <azul@riseup.net> | 2016-08-30 12:10:57 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-08-30 12:36:40 +0200 |
commit | b22e23eb9f5a1cb3e37ab2a26b1091183574f4e4 (patch) | |
tree | b3ca7f91dd78994c5d0164645922b3929b9177a3 /lib/nickserver/request_handlers/invalid_email_handler.rb | |
parent | 494e6f32daf0f6bf37321507b83848b4be087100 (diff) |
refactor: make the RequestHandler classes callable
Whenever a RequestHandler class is called we instantiate it with the request.
Then we call handle on the instance. This way we can access the request and
its content via accessors rather than only in the handle method.
Diffstat (limited to 'lib/nickserver/request_handlers/invalid_email_handler.rb')
-rw-r--r-- | lib/nickserver/request_handlers/invalid_email_handler.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/nickserver/request_handlers/invalid_email_handler.rb b/lib/nickserver/request_handlers/invalid_email_handler.rb index eaf8156..bb98f65 100644 --- a/lib/nickserver/request_handlers/invalid_email_handler.rb +++ b/lib/nickserver/request_handlers/invalid_email_handler.rb @@ -1,15 +1,21 @@ +require 'nickserver/request_handlers/base' require 'nickserver/email_address' require 'nickserver/error_response' module Nickserver module RequestHandlers - class InvalidEmailHandler - def call(request) + class InvalidEmailHandler < Base + + def handle return unless request.email - email = EmailAddress.new(request.email) ErrorResponse.new("Not a valid address") if email.invalid? end + protected + + def email + @email ||= EmailAddress.new(request.email) + end end end end |