Class: Groonga::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/groonga/client.rb,
lib/groonga/client/error.rb,
lib/groonga/client/command.rb,
lib/groonga/client/default.rb,
lib/groonga/client/version.rb,
lib/groonga/client/empty-request.rb,
lib/groonga/client/protocol/gqtp.rb,
lib/groonga/client/protocol/http.rb,
lib/groonga/client/response/base.rb,
lib/groonga/client/response/dump.rb,
lib/groonga/client/response/load.rb,
lib/groonga/client/response/quit.rb,
lib/groonga/client/script-syntax.rb,
lib/groonga/client/protocol/error.rb,
lib/groonga/client/response/check.rb,
lib/groonga/client/response/error.rb,
lib/groonga/client/response/defrag.rb,
lib/groonga/client/response/delete.rb,
lib/groonga/client/response/schema.rb,
lib/groonga/client/response/select.rb,
lib/groonga/client/response/status.rb,
lib/groonga/client/response/log-put.rb,
lib/groonga/client/response/register.rb,
lib/groonga/client/response/log-level.rb,
lib/groonga/client/response/lock-clear.rb,
lib/groonga/client/response/log-reopen.rb,
lib/groonga/client/response/table-list.rb,
lib/groonga/client/protocol/http/coolio.rb,
lib/groonga/client/protocol/http/thread.rb,
lib/groonga/client/response/cache-limit.rb,
lib/groonga/client/response/column-list.rb,
lib/groonga/client/response/table-create.rb,
lib/groonga/client/response/table-remove.rb,
lib/groonga/client/response/column-create.rb,
lib/groonga/client/response/column-remove.rb,
lib/groonga/client/response/column-rename.rb,
lib/groonga/client/protocol/http/synchronous.rb,
lib/groonga/client/protocol/http/path-resolvable.rb
Defined Under Namespace
Modules: Default, Protocol, Response, ScriptSyntax
Classes: Command, EmptyRequest, Error
Constant Summary
collapse
- VERSION =
"0.2.7"
- @@deafult_options =
{}
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/groonga/client.rb', line 90
def initialize(options={})
options = self.class.default_options.merge(options)
url = options[:url] || build_url(options)
url = URI.parse(url) unless url.is_a?(URI::Generic)
options[:url] = url
options[:read_timeout] ||= Default::READ_TIMEOUT
@connection = nil
case url.scheme
when "gqtp"
@connection = Groonga::Client::Protocol::GQTP.new(url, options)
when "http", "https"
@connection = Groonga::Client::Protocol::HTTP.new(url, options)
else
message = "unsupported scheme: <#{url.scheme}>: "
message << "supported: [gqtp, http, https]"
raise ArgumentError, message
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &block) ⇒ Object
179
180
181
182
183
184
185
|
# File 'lib/groonga/client.rb', line 179
def method_missing(name, *args, **kwargs, &block)
if groonga_command_name?(name)
execute(name, *args, **kwargs, &block)
else
super
end
end
|
Class Method Details
.default_options ⇒ Hash
Returns The default options for new.
36
37
38
|
# File 'lib/groonga/client.rb', line 36
def default_options
@@deafult_options
end
|
.default_options=(options) ⇒ Object
44
45
46
|
# File 'lib/groonga/client.rb', line 44
def default_options=(options)
@@deafult_options = options
end
|
.open(options = {}) ⇒ Client
.open(options = {}) {|client| ... } ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/groonga/client.rb', line 75
def open(options={}, &block)
client = new(options)
if block_given?
begin
yield(client)
ensure
client.close
end
else
client
end
end
|
Instance Method Details
#close ⇒ Boolean
#close({}) { ... } ⇒ #wait
Closes the opened client connection if the current connection is
still opened. You can't send a new command after you call this
method.
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/groonga/client.rb', line 127
def close(&block)
sync = !block_given?
if @connection
close_request = @connection.close do
yield unless sync
@connection = nil
end
if sync
close_request.wait
true
else
close_request
end
else
if sync
false
else
EmptyRequest.new
end
end
end
|
#execute(command_or_name, parameters = {}, &block) ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/groonga/client.rb', line 167
def execute(command_or_name, parameters={}, &block)
if command_or_name.is_a?(Groonga::Command::Base)
command = command_or_name
else
command_name = command_or_name
parameters = normalize_parameters(parameters)
command_class = Groonga::Command.find(command_name)
command = command_class.new(command_name, parameters)
end
execute_command(command, &block)
end
|
#load(parameters, &block) ⇒ Object
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/groonga/client.rb', line 149
def load(parameters, &block)
values = parameters[:values]
if values.is_a?(Array)
json = "["
values.each_with_index do |value, i|
if i.zero?
json << "\n"
else
json << ",\n"
end
json << JSON.generate(value)
end
json << "\n]"
parameters[:values] = json
end
execute(:load, parameters, &block)
end
|
#respond_to_missing?(name, include_private) ⇒ Boolean
187
188
189
190
191
192
193
|
# File 'lib/groonga/client.rb', line 187
def respond_to_missing?(name, include_private)
if groonga_command_name?(name)
true
else
super
end
end
|