In Files

Parent

Class/Module Index [+]

Quicksearch

UUID::Client

Every server needs a client. Client provides you with the single ultimate method: generate. Typically you'll use this instead of the local UUID generator:

UUID.server = UUID::SOCKET_NAME

Public Class Methods

new(address) click to toggle source
# File lib/uuid.rb, line 451
def initialize(address)
  @socket = connect(address)
  at_exit { close }
end

Public Instance Methods

close() click to toggle source

Close the socket.

# File lib/uuid.rb, line 489
def close
  @socket.shutdown if @socket
  @socket = nil
end
connect(address) click to toggle source

Returns UNIXSocket or TCPSocket from address. Returns argument if not a string, so can pass through.

# File lib/uuid.rb, line 468
def connect(address)
  return address unless String === address
  if address[0] == //
    sock = UNIXSocket.new(address)
  elsif address =~ /^(\d+\.\d+\.\d+\.\d+):(\d+)$/
    sock = TCPSocket.new($1, $2.to_i)
  else
    raise ArgumentError, "Don't know how to connect to #{address}"
  end
  sock.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) if defined?(TCP_NODELAY)
  sock
end
generate(format = :default) click to toggle source

Talks to server and returns new UUID in specified format.

# File lib/uuid.rb, line 457
def generate(format = :default)
  @socket.write "\00""
  uuid = @socket.read(36)
  return uuid if format == :default
  template = FORMATS[format]
  raise ArgumentError, "invalid UUID format #{format.inspect}" unless template
  template % uuid.split("-").map { |p| p.to_i(16) }
end
inspect() click to toggle source
# File lib/uuid.rb, line 484
def inspect
  @socket ? "Server on #{Socket.unpack_sockaddr_in(@socket.getsockname).reverse!.join(':')}" : "Connection closed"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.