-
Notifications
You must be signed in to change notification settings - Fork 0
/
netutils.rb
35 lines (34 loc) · 1.08 KB
/
netutils.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module NetUtils
def carp(arg)
if $verbose
case true
when arg.kind_of?(Exception)
puts "Error:" + arg.message
#puts "#{self.class.to_s.downcase}:" + arg.message
#puts arg.backtrace.collect{|s| "#{self.class.to_s.downcase}:" + s}.join("\n")
else
puts "#{self.class.to_s.downcase}:" + arg
end
end
end
def get_resource( resource )
$:.each do |lp|
lp << '/' unless lp =~ /\/$/
res = "#{lp}#{resource}.rb"
if lp =~ /http:\/\//i
begin
response = Net::HTTP.get_response(URI.parse(res))
if response.code.to_i == 200
return response.body
else
raise response.code
end
rescue Exception => e
raise e.message()
end
else
return File.read(res) if FileTest.exist?(res)
end
end
end
end