Class: LazyTsquery
Overview
LazyTsquery delays the connection and the execution of following commands (‘use`, `login`) until another command is executed. This allows to create ready-to-use Tsquery objects without ever hitting the server.
Instance Method Summary
collapse
Methods inherited from Tsquery
#initialize
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
44
45
46
|
# File 'lib/lazy_tsquery.rb', line 44
def method_missing(command, *args)
execute(command.to_s, *args)
end
|
Instance Method Details
#close ⇒ Object
67
68
69
70
|
# File 'lib/lazy_tsquery.rb', line 67
def close
__getobj__.close
rescue NoMethodError
end
|
#connect(lazy: true, **kwargs) ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/lazy_tsquery.rb', line 11
def connect(lazy: true, **kwargs)
if lazy
@connection_info = kwargs
nil
else
super(**kwargs)
end
end
|
#execute(command, *args) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/lazy_tsquery.rb', line 21
def execute(command, *args)
case command
when 'use', 'login'
@commands ||= []
@commands << [command, args]
nil
else
connect **@connection_info, lazy: false
@commands.each do |command, args|
super(command, *args)
end
@commands = []
super
end
end
|
#inspect ⇒ Object
62
63
64
|
# File 'lib/lazy_tsquery.rb', line 62
def inspect
__getobj__.inspect
end
|
#login(username: 'serveradmin', password:) ⇒ Object
54
55
56
57
58
59
|
# File 'lib/lazy_tsquery.rb', line 54
def login(username: 'serveradmin', password:)
execute 'login', username, password
nil
rescue Tsquery::Error
false
end
|
#respond_to_missing?(command) ⇒ Boolean
49
50
51
|
# File 'lib/lazy_tsquery.rb', line 49
def respond_to_missing?(command, *)
!!(command =~ /[[:alnum:]]$/)
end
|