Class: Godot
- Inherits:
-
Object
- Object
- Godot
- Defined in:
- lib/godot.rb,
lib/godot/version.rb
Constant Summary collapse
- VERSION =
"0.3.0"
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#trace ⇒ Object
Returns the value of attribute trace.
Class Method Summary collapse
- .match(host, port, pattern, path = "", options = "-ks") ⇒ Object
- .match!(host, port, pattern, path = "", options = "-ks") ⇒ Object
- .wait(host, port) ⇒ Object
- .wait!(host, port) ⇒ Object
Instance Method Summary collapse
-
#initialize(host, port, options = {}) ⇒ Godot
constructor
A new instance of Godot.
- #match(pattern, path = "", options = "-ks") ⇒ Object
- #match!(pattern, path = "", options = "-ks") ⇒ Object
- #wait ⇒ Object
- #wait! ⇒ Object
Constructor Details
#initialize(host, port, options = {}) ⇒ Godot
Returns a new instance of Godot.
25 26 27 28 29 30 31 |
# File 'lib/godot.rb', line 25 def initialize(host, port, = {}) @host = host @port = port @interval = [:interval] || 1 @trace = [:trace] || false @timeout = [:timeout] || 10 end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/godot.rb', line 6 def host @host end |
#interval ⇒ Object
Returns the value of attribute interval.
7 8 9 |
# File 'lib/godot.rb', line 7 def interval @interval end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/godot.rb', line 6 def port @port end |
#timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/godot.rb', line 7 def timeout @timeout end |
#trace ⇒ Object
Returns the value of attribute trace.
7 8 9 |
# File 'lib/godot.rb', line 7 def trace @trace end |
Class Method Details
.match(host, port, pattern, path = "", options = "-ks") ⇒ Object
21 22 23 |
# File 'lib/godot.rb', line 21 def self.match(host, port, pattern, path = "", = "-ks") new(host, port).match(pattern, path, ) end |
.match!(host, port, pattern, path = "", options = "-ks") ⇒ Object
17 18 19 |
# File 'lib/godot.rb', line 17 def self.match!(host, port, pattern, path = "", = "-ks") new(host, port).match!(pattern, path, ) end |
.wait(host, port) ⇒ Object
13 14 15 |
# File 'lib/godot.rb', line 13 def self.wait(host, port) new(host, port).wait end |
.wait!(host, port) ⇒ Object
9 10 11 |
# File 'lib/godot.rb', line 9 def self.wait!(host, port) new(host, port).wait! end |
Instance Method Details
#match(pattern, path = "", options = "-ks") ⇒ Object
63 64 65 66 67 68 |
# File 'lib/godot.rb', line 63 def match(pattern, path = "", = "-ks") match!(pattern, path, ) true rescue Timeout::Error false end |
#match!(pattern, path = "", options = "-ks") ⇒ Object
57 58 59 60 61 |
# File 'lib/godot.rb', line 57 def match!(pattern, path = "", = "-ks") Timeout.timeout(timeout) do sleep interval until `curl #{options} http://#{host}:#{port}/#{path}` =~ pattern end end |
#wait ⇒ Object
50 51 52 53 54 55 |
# File 'lib/godot.rb', line 50 def wait wait! true rescue Timeout::Error false end |
#wait! ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/godot.rb', line 33 def wait! socket = nil Timeout.timeout(timeout) do until socket begin Timeout.timeout(interval) do socket = TCPSocket.open(host, port) end rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, Timeout::Error, Errno::EHOSTUNREACH, Errno::EHOSTDOWN $stderr.putc "." if trace end end end ensure socket.close if socket end |