Customizable query handler #189

Closed
wants to merge 2 commits into
from

Projects

None yet

1 participant

@weppos
Owner

This (experimental) feature allows you to write custom query handlers and replace the default synchronous socket-based handler with any custom handler.

The query handler handles is the low-level connection between the library and the external WHOIS source. As of today, the only way to use a different connection mechanism/technology is by monkey-patching the library.

Why you may want to change the query handler?

There are hundreds of reasons why you may want to do that. Here's a few:

  • In your testing environment you might want to use a TestHandler to avoid performing real external connections. If you ever used the whois library in a real Ruby app with tests, you probably ended up using a lot of mocked and stubbed objects.
  • To perform super-fast multiple lookups, you may want to write an asyncronous handler using EM, Celluloid or your favourite async library
  • If you need to interact with multiple systems, you might want to use a distributed architecture or a queue system.
added some commits Oct 16, 2012
@weppos Rewrite the way we handle socket internally
I will probably move some code into classes, instead of using namespaced_methods.

#query_handle exists because it's the best method to be hooked if you want to instrument and measure the queries. It sits just before the socket connection, can handle the errors and exposes the final list of args.
66538fc
@weppos Extract default Socket query handler into its own class
This allows swappable query handler.

Do you want to use an EM async handler? Write the class and set Base.query_handler to your handler.
Do you want a test handler to avoid external connections in testing? Yes, I do!
99fc791
@weppos
Owner

@mikejarema @JustinCampbell @tpalmer do you have any feedback?

@weppos weppos closed this in 8aa56d1 Oct 29, 2012
@weppos weppos was assigned Oct 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment