Class: Godot

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

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ Godot

Returns a new instance of Godot.



24
25
26
27
# File 'lib/godot.rb', line 24

def initialize(host, port)
  @host = host
  @port = port
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#intervalObject



29
30
31
# File 'lib/godot.rb', line 29

def interval
  @interval || 1
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

#timeoutObject



33
34
35
# File 'lib/godot.rb', line 33

def timeout
  @timeout || 10
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 = "", options = "-ks")
  new(host, port).match(pattern, path, options)
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 = "", options = "-ks")
  new(host, port).match!(pattern, path, options)
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



64
65
66
67
68
69
# File 'lib/godot.rb', line 64

def match(pattern, path = "", options = "-ks")
  match!(pattern, options)
  true
rescue Timeout::Error
  false
end

#match!(pattern, path = "", options = "-ks") ⇒ Object



58
59
60
61
62
# File 'lib/godot.rb', line 58

def match!(pattern, path = "", options = "-ks")
  Timeout.timeout(timeout) do
    sleep interval until `curl #{options} http://#{host}:#{port}/#{path}` =~ pattern
  end
end

#waitObject



51
52
53
54
55
56
# File 'lib/godot.rb', line 51

def wait
  wait!
  true
rescue Timeout::Error
  false
end

#wait!Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/godot.rb', line 37

def wait!
  Timeout.timeout(timeout) do
    socket = nil
    until socket
      begin
        Timeout.timeout(interval) do
          socket = TCPSocket.open(host, port)
        end
      rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, Timeout::Error, Errno::EHOSTUNREACH
      end
    end
  end
end