Class: Whois::Server::Adapters::Base
- Inherits:
-
Object
- Object
- Whois::Server::Adapters::Base
- Defined in:
- lib/whois/server/adapters/base.rb
Direct Known Subclasses
Afilias, Arin, Arpa, Formatted, None, NotImplemented, Standard, Verisign, Web
Constant Summary collapse
- DEFAULT_WHOIS_PORT =
Default WHOIS request port.
43- DEFAULT_BIND_HOST =
Default bind hostname.
"0.0.0.0"
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#allocation ⇒ String
readonly
The allocation this server is responsible for.
-
#buffer ⇒ Array
readonly
private
Temporary internal response buffer.
-
#host ⇒ String?
readonly
The server hostname.
-
#options ⇒ Hash
readonly
Optional adapter properties.
-
#type ⇒ Symbol
readonly
The type of WHOIS server.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Checks self and other for equality.
-
#configure(settings) ⇒ Hash
Merges given
settingsinto current #options. -
#initialize(type, allocation, host, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#lookup(string) ⇒ Whois::Record
Performs a Whois lookup for
stringusing the current server adapter. -
#query_handler ⇒ Object
Gets the current query handler for this class.
-
#request(string) ⇒ void
abstract
Performs the real WHOIS request.
Constructor Details
#initialize(type, allocation, host, options = {}) ⇒ Base
54 55 56 57 58 59 |
# File 'lib/whois/server/adapters/base.rb', line 54 def initialize(type, allocation, host, = {}) @type = type @allocation = allocation @host = host = || {} end |
Class Attribute Details
.query_handler ⇒ Object
22 23 24 |
# File 'lib/whois/server/adapters/base.rb', line 22 def query_handler @query_handler ||= SocketHandler.new end |
Instance Attribute Details
#allocation ⇒ String (readonly)
37 38 39 |
# File 'lib/whois/server/adapters/base.rb', line 37 def allocation @allocation end |
#buffer ⇒ Array (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Temporary internal response buffer.
47 48 49 |
# File 'lib/whois/server/adapters/base.rb', line 47 def buffer @buffer end |
#host ⇒ String? (readonly)
39 40 41 |
# File 'lib/whois/server/adapters/base.rb', line 39 def host @host end |
#options ⇒ Hash (readonly)
41 42 43 |
# File 'lib/whois/server/adapters/base.rb', line 41 def end |
#type ⇒ Symbol (readonly)
35 36 37 |
# File 'lib/whois/server/adapters/base.rb', line 35 def type @type end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Checks self and other for equality.
66 67 68 69 70 71 72 73 74 |
# File 'lib/whois/server/adapters/base.rb', line 66 def ==(other) equal?(other) || ( other.is_a?(self.class) && type == other.type && allocation == other.allocation && host == other.host && == other. ) end |
#configure(settings) ⇒ Hash
Merges given settings into current #options.
83 84 85 86 |
# File 'lib/whois/server/adapters/base.rb', line 83 def configure(settings) @host = settings[:host] if settings[:host] .merge!(settings) end |
#lookup(string) ⇒ Whois::Record
Performs a Whois lookup for string using the current server adapter.
Internally, this method calls #request using the Template Method design pattern.
server.lookup("google.com")
# => Whois::Record
98 99 100 101 |
# File 'lib/whois/server/adapters/base.rb', line 98 def lookup(string) parts = buffer_start { request(string) } Whois::Record.new(self, parts) end |
#query_handler ⇒ Object
Gets the current query handler for this class.
122 123 124 |
# File 'lib/whois/server/adapters/base.rb', line 122 def query_handler self.class.query_handler end |
#request(string) ⇒ void
This method returns an undefined value.
Performs the real WHOIS request.
This method is not implemented in Whois::Server::Adapters::Base class, it is intended to be overwritten in the concrete subclasses. This is the heart of the Template Method design pattern.
113 114 115 |
# File 'lib/whois/server/adapters/base.rb', line 113 def request(string) raise NotImplementedError end |