Class: Schatz::Input::Connection
- Inherits:
-
Object
- Object
- Schatz::Input::Connection
- Defined in:
- lib/schatz/input/connection.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#description ⇒ Object
Returns the value of attribute description.
-
#gcm ⇒ Object
Returns the value of attribute gcm.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#result ⇒ Object
Returns the value of attribute result.
-
#scheme ⇒ Object
Returns the value of attribute scheme.
Instance Method Summary collapse
- #check ⇒ Object
- #direct? ⇒ Boolean
- #eql?(b) ⇒ Boolean
- #host_check ⇒ Object
- #http? ⇒ Boolean
- #https? ⇒ Boolean
-
#initialize {|_self| ... } ⇒ Connection
constructor
A new instance of Connection.
- #link? ⇒ Boolean
- #link_check ⇒ Object
- #mark ⇒ Object
- #mark_hosts ⇒ Object
- #mark_links ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Connection
Returns a new instance of Connection.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/schatz/input/connection.rb', line 5 def initialize @port = 80 @scheme = "http" yield self if @port=="" || @port==0 case @scheme when "http" @port = 80 when "https" @port = 443 end end end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
4 5 6 |
# File 'lib/schatz/input/connection.rb', line 4 def color @color end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/schatz/input/connection.rb', line 4 def description @description end |
#gcm ⇒ Object
Returns the value of attribute gcm.
4 5 6 |
# File 'lib/schatz/input/connection.rb', line 4 def gcm @gcm end |
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/schatz/input/connection.rb', line 4 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/schatz/input/connection.rb', line 4 def port @port end |
#result ⇒ Object
Returns the value of attribute result.
4 5 6 |
# File 'lib/schatz/input/connection.rb', line 4 def result @result end |
#scheme ⇒ Object
Returns the value of attribute scheme.
4 5 6 |
# File 'lib/schatz/input/connection.rb', line 4 def scheme @scheme end |
Instance Method Details
#check ⇒ Object
66 67 68 |
# File 'lib/schatz/input/connection.rb', line 66 def check direct? ? host_check : link_check end |
#direct? ⇒ Boolean
45 46 47 |
# File 'lib/schatz/input/connection.rb', line 45 def direct? scheme.downcase == "tcp" || scheme.downcase == "udp" end |
#eql?(b) ⇒ Boolean
18 19 20 |
# File 'lib/schatz/input/connection.rb', line 18 def eql?(b) self.scheme == b.scheme && self.host == b.host && self.port == b.port && self.gcm == b.gcm ? true : false end |
#host_check ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/schatz/input/connection.rb', line 84 def host_check begin self.result = Schemes::DirectTcp.direct_test(self.host, self.port, 0.5) ? "open" : "closed" rescue Exception => e self.result = "closed" end self end |
#http? ⇒ Boolean
33 34 35 |
# File 'lib/schatz/input/connection.rb', line 33 def http? @scheme="http" end |
#https? ⇒ Boolean
37 38 39 |
# File 'lib/schatz/input/connection.rb', line 37 def https? @scheme="https" end |
#link? ⇒ Boolean
49 50 51 |
# File 'lib/schatz/input/connection.rb', line 49 def link? scheme.downcase == "http" || scheme.downcase == "https" end |
#link_check ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/schatz/input/connection.rb', line 69 def link_check raise ArgumentError unless @proxy begin self.result = case scheme when "http" Schemes::ProxyHttp.http_test(self, @proxy) when "https" Schemes::ProxyHttps.https_test(self, @proxy) end rescue Exception => e self.result = e. end self end |
#mark ⇒ Object
41 42 43 |
# File 'lib/schatz/input/connection.rb', line 41 def mark direct? ? mark_hosts : mark_links end |
#mark_hosts ⇒ Object
53 54 55 |
# File 'lib/schatz/input/connection.rb', line 53 def mark_hosts self.color = result == "open" ? "green" : "red" end |
#mark_links ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/schatz/input/connection.rb', line 57 def mark_links self.color, self.description= case result when /30[12]/ then ["green", "Redirection to websso"] when "200" then ["green", "OK"] when /40[13]/ then ["green", "Error authorization"] else ["red", result] end end |