Module: Specjour::SocketHelper

Included in:
Dispatcher, Manager, RsyncDaemon, Worker
Defined in:
lib/specjour/socket_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_uriObject



19
20
21
# File 'lib/specjour/socket_helper.rb', line 19

def current_uri
  @current_uri ||= new_uri
end

#hostnameObject



11
12
13
# File 'lib/specjour/socket_helper.rb', line 11

def hostname
  @hostname ||= Socket.gethostname
end

#ip_from_hostname(hostname) ⇒ Object



5
6
7
8
9
# File 'lib/specjour/socket_helper.rb', line 5

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

#local_ipObject



15
16
17
# File 'lib/specjour/socket_helper.rb', line 15

def local_ip
  @local_ip ||= UDPSocket.open {|s| s.connect('74.125.224.103', 1); s.addr.last }
end

#new_uriObject



23
24
25
# File 'lib/specjour/socket_helper.rb', line 23

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