Class: Godot
- Inherits:
-
Object
- Object
- Godot
- Defined in:
- lib/godot.rb,
lib/godot/version.rb
Constant Summary collapse
- VERSION =
"0.2.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.
24 25 26 27 28 29 30 |
# File 'lib/godot.rb', line 24 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.
5 6 7 |
# File 'lib/godot.rb', line 5 def host @host end |
#interval ⇒ Object
Returns the value of attribute interval.
6 7 8 |
# File 'lib/godot.rb', line 6 def interval @interval end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/godot.rb', line 5 def port @port end |
#timeout ⇒ Object
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/godot.rb', line 6 def timeout @timeout end |
#trace ⇒ Object
Returns the value of attribute trace.
6 7 8 |
# File 'lib/godot.rb', line 6 def trace @trace end |
Class Method Details
.match(host, port, pattern, path = "", options = "-ks") ⇒ Object
20 21 22 |
# File 'lib/godot.rb', line 20 def self.match(host, port, pattern, path = "", = "-ks") new(host, port).match(pattern, path, ) end |
.match!(host, port, pattern, path = "", options = "-ks") ⇒ Object
16 17 18 |
# File 'lib/godot.rb', line 16 def self.match!(host, port, pattern, path = "", = "-ks") new(host, port).match!(pattern, path, ) end |
.wait(host, port) ⇒ Object
12 13 14 |
# File 'lib/godot.rb', line 12 def self.wait(host, port) new(host, port).wait end |
.wait!(host, port) ⇒ Object
8 9 10 |
# File 'lib/godot.rb', line 8 def self.wait!(host, port) new(host, port).wait! end |
Instance Method Details
#match(pattern, path = "", options = "-ks") ⇒ Object
62 63 64 65 66 67 |
# File 'lib/godot.rb', line 62 def match(pattern, path = "", = "-ks") match!(pattern, path, ) true rescue Timeout::Error false end |
#match!(pattern, path = "", options = "-ks") ⇒ Object
56 57 58 59 60 |
# File 'lib/godot.rb', line 56 def match!(pattern, path = "", = "-ks") Timeout.timeout(timeout) do sleep interval until `curl #{} http://#{host}:#{port}/#{path}` =~ pattern end end |
#wait ⇒ Object
49 50 51 52 53 54 |
# File 'lib/godot.rb', line 49 def wait wait! true rescue Timeout::Error false end |
#wait! ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/godot.rb', line 32 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 |