Sha256: e6214fc283b958f3c097d01f324d2ce34a2f6669eda6df01ea2cb8438dd479a5

Contents?: true

Size: 624 Bytes

Versions: 7

Compression:

Stored size: 624 Bytes

Contents

module Specjour
  module SocketHelper
    Socket.do_not_reverse_lookup = true

    def ip_from_hostname(hostname)
      Socket.getaddrinfo(hostname, nil, Socket::AF_INET, Socket::SOCK_STREAM).first.fetch(3)
    rescue SocketError
      hostname
    end

    def hostname
      @hostname ||= Socket.gethostname
    end

    def current_uri
      @current_uri ||= new_uri
    end

    def new_uri
      URI::Generic.build :host => faux_server[2], :port => faux_server[1]
    end

    protected

    def faux_server
      server = TCPServer.new('0.0.0.0', nil)
      server.addr
    ensure
      server.close
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
specjour-0.5.6 lib/specjour/socket_helper.rb
specjour-0.5.5 lib/specjour/socket_helper.rb
specjour-0.5.4 lib/specjour/socket_helper.rb
specjour-0.5.2 lib/specjour/socket_helper.rb
specjour-0.5.0 lib/specjour/socket_helper.rb
specjour-0.4.1 lib/specjour/socket_helper.rb
specjour-0.4.0 lib/specjour/socket_helper.rb