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
settings
into current #options. -
#initialize(type, allocation, host, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#lookup(string) ⇒ Whois::Record
Performs a Whois lookup for
string
using 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
Returns a new instance of Base.
55 56 57 58 59 60 |
# File 'lib/whois/server/adapters/base.rb', line 55 def initialize(type, allocation, host, = {}) @type = type @allocation = allocation @host = host @options = || {} end |
Class Attribute Details
.query_handler ⇒ Object
23 24 25 |
# File 'lib/whois/server/adapters/base.rb', line 23 def query_handler @query_handler ||= SocketHandler.new end |
Instance Attribute Details
#allocation ⇒ String (readonly)
Returns The allocation this server is responsible for.
38 39 40 |
# File 'lib/whois/server/adapters/base.rb', line 38 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.
48 49 50 |
# File 'lib/whois/server/adapters/base.rb', line 48 def buffer @buffer end |
#host ⇒ String? (readonly)
Returns The server hostname.
40 41 42 |
# File 'lib/whois/server/adapters/base.rb', line 40 def host @host end |
#options ⇒ Hash (readonly)
Returns Optional adapter properties.
42 43 44 |
# File 'lib/whois/server/adapters/base.rb', line 42 def @options end |
#type ⇒ Symbol (readonly)
Returns The type of WHOIS server.
36 37 38 |
# File 'lib/whois/server/adapters/base.rb', line 36 def type @type end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Checks self and other for equality.
67 68 69 70 71 72 73 74 75 |
# File 'lib/whois/server/adapters/base.rb', line 67 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.
84 85 86 87 |
# File 'lib/whois/server/adapters/base.rb', line 84 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
99 100 101 102 |
# File 'lib/whois/server/adapters/base.rb', line 99 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.
123 124 125 |
# File 'lib/whois/server/adapters/base.rb', line 123 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.
114 115 116 |
# File 'lib/whois/server/adapters/base.rb', line 114 def request(string) raise NotImplementedError end |