Module: ClientHelper
- Defined in:
- app/helpers/client_helper.rb
Instance Method Summary collapse
- #check_interminably(host, port) ⇒ Object
- #check_tag(cid) ⇒ Object
- #client_check(host, port = 9102) ⇒ Object
- #client_image ⇒ Object
- #host_for_client(client) ⇒ Object
Instance Method Details
#check_interminably(host, port) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/helpers/client_helper.rb', line 8 def check_interminably(host, port) begin s = TCPSocket.new(host, port) s.close s ? "okay.png" : "error.png" rescue SocketError "dunno.png" rescue "error.png" end end |
#check_tag(cid) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/client_helper.rb', line 31 def check_tag(cid) if cid == 0 content_tag('td', content_tag('a', "OK?", :href => "#", :onclick => "return check_through(#{@clients.size})")) else content_tag('td', content_tag('a', content_tag('div', image_tag('dunno.png', :class => "em1"), :class => "center", :id => "client-#{cid}"), :href => "#", :onclick => "return check(#{cid})")) end end |
#client_check(host, port = 9102) ⇒ Object
20 21 22 23 |
# File 'app/helpers/client_helper.rb', line 20 def client_check(host, port = 9102) t = Thread.new { check_interminably(host, port) } t.join(5) ? t.value : "error.png" end |
#client_image ⇒ Object
25 26 27 28 29 |
# File 'app/helpers/client_helper.rb', line 25 def client_image @client = Client.find(params[:id]) host = host_for_client(@client.name) @image = client_check(host) end |
#host_for_client(client) ⇒ Object
4 5 6 |
# File 'app/helpers/client_helper.rb', line 4 def host_for_client(client) host = CLIENT_MAP[client] or client.gsub(/-fd$/, '') end |