Class: Godot

Inherits:
Object
  • Object
show all
Defined in:
lib/godot.rb,
lib/godot/version.rb

Constant Summary collapse

VERSION =
"0.3.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @host = host
  @port = port
  @interval = options[:interval] || 1
  @trace = options[:trace] || false
  @timeout = options[:timeout] || 10
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/godot.rb', line 6

def host
  @host
end

#intervalObject

Returns the value of attribute interval.



7
8
9
# File 'lib/godot.rb', line 7

def interval
  @interval
end

#portObject (readonly)

Returns the value of attribute port.



6
7
8
# File 'lib/godot.rb', line 6

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout.



7
8
9
# File 'lib/godot.rb', line 7

def timeout
  @timeout
end

#traceObject

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 = "", options = "-ks")
  new(host, port).match(pattern, path, options)
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 = "", options = "-ks")
  new(host, port).match!(pattern, path, options)
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 = "", options = "-ks")
  match!(pattern, path, options)
  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 = "", options = "-ks")
  Timeout.timeout(timeout) do
    sleep interval until `curl #{options} http://#{host}:#{port}/#{path}` =~ pattern
  end
end

#waitObject



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