Class: RetryingTsquery

Inherits:
Tsquery show all
Defined in:
lib/retrying_tsquery.rb

Overview

Instance Method Summary collapse

Methods inherited from Tsquery

#close, #initialize, #login

Constructor Details

This class inherits a constructor from Tsquery

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(command, *args) ⇒ Object



30
31
32
# File 'lib/retrying_tsquery.rb', line 30

def method_missing(command, *args)
  execute(command.to_s, *args)
end

Instance Method Details

#connect(times: 3, sleep: Kernel.method(:sleep), **keyword_args) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/retrying_tsquery.rb', line 7

def connect(times: 3, sleep: Kernel.method(:sleep), **keyword_args)
  super(**keyword_args)
rescue Errno::ECONNREFUSED
  sleep.call 0.5
  retry if (times -= 1) > 0
  Kernel.raise
end

#execute(*args, times: 3, sleep: Kernel.method(:sleep), **keyword_args) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/retrying_tsquery.rb', line 16

def execute(*args, times: 3, sleep: Kernel.method(:sleep), **keyword_args)
  super(*args, **keyword_args)
rescue Tsquery::UnknownCommand
  Kernel.raise
rescue Tsquery::Error
  sleep.call 0.5
  retry if (times -= 1) > 0
  Kernel.raise
end

#inspectObject



40
41
42
# File 'lib/retrying_tsquery.rb', line 40

def inspect
  __getobj__.inspect
end

#respond_to_missing?(command) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/retrying_tsquery.rb', line 35

def respond_to_missing?(command, *)
  !!(command =~ /[[:alnum:]]$/)
end