Class: Whois::Server::Adapters::Base

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, options = {})
  @type       = type
  @allocation = allocation
  @host       = host
  @options    = options || {}
end

Class Attribute Details

.query_handlerObject



22
23
24
# File 'lib/whois/server/adapters/base.rb', line 22

def query_handler
  @query_handler ||= SocketHandler.new
end

Instance Attribute Details

#allocationString (readonly)



37
38
39
# File 'lib/whois/server/adapters/base.rb', line 37

def allocation
  @allocation
end

#bufferArray (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

#hostString? (readonly)



39
40
41
# File 'lib/whois/server/adapters/base.rb', line 39

def host
  @host
end

#optionsHash (readonly)



41
42
43
# File 'lib/whois/server/adapters/base.rb', line 41

def options
  @options
end

#typeSymbol (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 &&
    options == other.options
  )
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]
  options.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_handlerObject

Gets the current query handler for this class.

See Also:

  • Whois::Servers::Adapters::Base.query_handler


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 is abstract.

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.

Raises:

  • (NotImplementedError)


113
114
115
# File 'lib/whois/server/adapters/base.rb', line 113

def request(string)
  raise NotImplementedError
end