Class: Sbuilder::Utils::NetIo

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/netio.rb

Class Method Summary collapse

Class Method Details

.do_read_lines(uri) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/utils/netio.rb', line 35

def do_read_lines( uri  )
  begin
    open( uri ).read
  rescue => e
    msg = "Error #{e}, when reading from uri '#{uri}'"
    raise msg
  end
end

.read_lines(uri) ⇒ String

read line from uri

Returns:



26
27
28
29
30
31
32
33
# File 'lib/utils/netio.rb', line 26

def read_lines( uri  )
  
  # network access && create cache
  lines = do_read_lines( uri )

  return lines
  
end

.uri_exist?(uri) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
# File 'lib/utils/netio.rb', line 13

def uri_exist?( uri )
  if uri =~ URI::regexp
    url = URI.parse( uri )
    Net::HTTP.start(url.host, url.port) { |http|
      return http.head(url.request_uri).code == "200"
    }
  else
    return File.exist?( uri )
  end
end