Class: WaitForSolr

Inherits:
Struct
  • Object
show all
Defined in:
lib/wait_for_solr.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



3
4
5
# File 'lib/wait_for_solr.rb', line 3

def port
  @port
end

#timeoutObject

Returns the value of attribute timeout

Returns:

  • (Object)

    the current value of timeout



3
4
5
# File 'lib/wait_for_solr.rb', line 3

def timeout
  @timeout
end

Class Method Details

.on(port, timeout, &block) ⇒ Object



4
5
6
# File 'lib/wait_for_solr.rb', line 4

def self.on port, timeout, &block
  new(port, timeout).wait &block
end

.running_on?(port) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/wait_for_solr.rb', line 8

def self.running_on? port
  new(port).responding?
end

Instance Method Details

#responding?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/wait_for_solr.rb', line 21

def responding?
  system %(curl -o /dev/null "http://localhost:#{port}/solr" > /dev/null 2>&1)
end

#wait(&block) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/wait_for_solr.rb', line 12

def wait &block
  Timeout::timeout timeout do
    until responding? do
      block.call
      sleep 1
    end
  end
end