Module: Hudkins::Common
Overview
common methods available for all classes
Instance Method Summary collapse
-
#check_host_availability ⇒ Object
TODO host is not universally accessible so this method might not belong here..
-
#get(*args) ⇒ Object
accessor methods for child classes to get.
-
#host_available? ⇒ Boolean
TODO host is not universally accessible so this method might not belong here..
-
#hudkins ⇒ Object
– these classes are being included in the @hudkins class.
-
#inspect(string = nil) ⇒ Object
hide instance variables.
-
#post(*args) ⇒ Object
accessor methods for child classes to post.
-
#url_escape(msg) ⇒ Object
Description useful for escaping parameters to be sent to #get/#post.
Instance Method Details
#check_host_availability ⇒ Object
TODO host is not universally accessible so this method might not belong here.. Raise TimeoutError unless hudson host is responding within specified number of seconds.
62 63 64 65 66 |
# File 'lib/hudkins/common.rb', line 62 def check_host_availability # host is URI. msg = "`%s' did not respond within the set number of seconds." % [ host.host ] raise TimeoutError, msg unless host_available? end |
#get(*args) ⇒ Object
accessor methods for child classes to get
38 39 40 |
# File 'lib/hudkins/common.rb', line 38 def get *args @hudkins.get *args end |
#host_available? ⇒ Boolean
TODO host is not universally accessible so this method might not belong here..
Notes
My Hudson server is not publicially accessible so when I can’t connect, Socket#getaddrinfo (RestClient) times out after more than 20 seconds! I created a healper class Hudkins::HostLookup to timeout Socket#getaddrinfo after Hudkins::HostLookup#TIMEOUT seconds (defaults to 2).
55 56 57 |
# File 'lib/hudkins/common.rb', line 55 def host_available? HostLookup.available? @host, @options[:host_timeout] end |
#hudkins ⇒ Object
– these classes are being included in the @hudkins class. ++
32 33 34 |
# File 'lib/hudkins/common.rb', line 32 def hudkins @hudkins end |
#inspect(string = nil) ⇒ Object
hide instance variables
6 7 8 9 |
# File 'lib/hudkins/common.rb', line 6 def inspect( string = nil ) new_string = " " << string if string "#<%s:0x%x%s>" % [self.class, (self.object_id << 1), new_string] end |
#post(*args) ⇒ Object
accessor methods for child classes to post
44 45 46 |
# File 'lib/hudkins/common.rb', line 44 def post *args @hudkins.post *args end |
#url_escape(msg) ⇒ Object
Description
useful for escaping parameters to be sent to #get/#post
Parameters
Hash
-
converts a simple one dimentional hash to a url parameter query string and uri escapes it.
else
-
converts to string and uri escapes it.
19 20 21 22 23 24 25 26 |
# File 'lib/hudkins/common.rb', line 19 def url_escape msg case msg when Hash then URI.escape( msg.map {|k,v| "#{k}=#{v}" }.join("&") ) else URI.escape( msg.to_s ) end end |