diff options
author | Azul <azul@riseup.net> | 2016-08-27 09:09:07 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-08-27 09:09:07 +0200 |
commit | 47343fad827ac2bef2ed7bc08768e4e58ac9a95f (patch) | |
tree | 2d4645905ef0aec6546cb0934d0ef73ea9a1808a /lib/nickserver | |
parent | decdf85a8b2713fddf13888b48810d59b0ec2189 (diff) |
refactor: push down adapter dependency injection to sources
The original idea was that we would have all the celluloid related things
injected in reel_server. However it seems unlikely that we will use a
different http system anytime soon.
Removing some layers of dependency injection to reduce complexity. We
can easily bring this back if we want.
Diffstat (limited to 'lib/nickserver')
-rw-r--r-- | lib/nickserver/reel_server.rb | 2 | ||||
-rw-r--r-- | lib/nickserver/request_handler.rb | 28 | ||||
-rw-r--r-- | lib/nickserver/source.rb | 3 |
3 files changed, 9 insertions, 24 deletions
diff --git a/lib/nickserver/reel_server.rb b/lib/nickserver/reel_server.rb index 6f05e0b..549b738 100644 --- a/lib/nickserver/reel_server.rb +++ b/lib/nickserver/reel_server.rb @@ -32,7 +32,7 @@ module Nickserver protected def handler_for(request) - RequestHandler.new(request, Nickserver::Adapters::CelluloidHttp.new) + RequestHandler.new(request) end def params(request) diff --git a/lib/nickserver/request_handler.rb b/lib/nickserver/request_handler.rb index da9bcb3..239ac5f 100644 --- a/lib/nickserver/request_handler.rb +++ b/lib/nickserver/request_handler.rb @@ -33,9 +33,8 @@ module Nickserver attr_reader :params, :headers end - def initialize(responder, adapter) + def initialize(responder) @responder = responder - @adapter = adapter end def respond_to(params, headers) @@ -57,9 +56,9 @@ module Nickserver def handler_for_request(request) if request.email - EmailHandler.new adapter + EmailHandler.new elsif request.fingerprint - FingerprintHandler.new adapter + FingerprintHandler.new else Proc.new { Nickserver::Response.new(404, "Not Found\n") } end @@ -67,10 +66,6 @@ module Nickserver class EmailHandler - def initialize(adapter) - @adapter = adapter - end - def call(request) email = EmailAddress.new(request.email) if email.invalid? @@ -84,9 +79,9 @@ module Nickserver def send_key(email, request) if local_address?(email, request) - source = Nickserver::CouchDB::Source.new(adapter) + source = Nickserver::CouchDB::Source.new else - source = Nickserver::Hkp::Source.new(adapter) + source = Nickserver::Hkp::Source.new end source.query(email) rescue MissingHostHeader @@ -102,29 +97,20 @@ module Nickserver def local_address?(email, request) email.domain?(Config.domain || request.domain) end - - attr_reader :adapter end class FingerprintHandler - def initialize(adapter) - @adapter = adapter - end - def call(request) fingerprint = request.fingerprint if fingerprint.length == 40 && !fingerprint[/\H/] - source = Nickserver::Hkp::Source.new(adapter) + source = Nickserver::Hkp::Source.new source.get_key_by_fingerprint(fingerprint) else ErrorResponse.new('Fingerprint invalid: ' + fingerprint) end end - protected - - attr_reader :adapter end class ErrorResponse < Nickserver::Response @@ -138,7 +124,7 @@ module Nickserver responder.respond status, content end - attr_reader :responder, :adapter + attr_reader :responder class MissingHostHeader < StandardError end diff --git a/lib/nickserver/source.rb b/lib/nickserver/source.rb index b8135da..78f245b 100644 --- a/lib/nickserver/source.rb +++ b/lib/nickserver/source.rb @@ -1,13 +1,12 @@ module Nickserver class Source - def initialize(adapter) + def initialize(adapter = Nickserver::Adapters::CelluloidHttp.new) @adapter = adapter end protected attr_reader :adapter - end end |