Kosuke Asami
null+****@clear*****
Tue Jul 23 14:11:47 JST 2013
Kosuke Asami 2013-07-23 14:11:47 +0900 (Tue, 23 Jul 2013) New Revision: 43b6da3f64768f5e0c953d1d11e02bc4e37c0e17 https://github.com/groonga/fluent-plugin-droonga/commit/43b6da3f64768f5e0c953d1d11e02bc4e37c0e17 Message: adapter_select: extract convert methods as a class for "select" command Added files: lib/droonga/plugin/adapter_select.rb Modified files: lib/droonga/plugin/adapter_groonga.rb test/plugin/adapter/groonga/test_select.rb Modified: lib/droonga/plugin/adapter_groonga.rb (+5 -51) =================================================================== --- lib/droonga/plugin/adapter_groonga.rb 2013-07-23 14:00:40 +0900 (e326f6a) +++ lib/droonga/plugin/adapter_groonga.rb 2013-07-23 14:11:47 +0900 (9d9e505) @@ -22,60 +22,14 @@ module Droonga command :select def select(select_request) - search_request = select_convert_request(select_request) + command = Select.new + search_request = command.select_convert_request(select_request) post(search_request) do |search_response| - select_convert_response(search_response) + command.select_convert_response(search_response) end :selected end - - def select_convert_request(select_request) - table = select_request["table"] - output_columns = select_request["output_columns"] - attributes = output_columns.split(/, */) - - { - "queries" => { - table => { - "source" => table, - "output" => { - "elements" => [ - "startTime", - "elapsedTime", - "count", - "attributes", - "records", - ], - "attributes" => attributes, - }, - } - } - } - end - - def select_convert_response(search_response) - select_responses = search_response.collect do |key, value| - status_code = 0 - - start_time = value["startTime"] - start_time_in_unix_time = Time.parse(start_time).to_f - elapsed_time = value["elapsedTime"] - count = value["count"] - - attributes = value["attributes"] - converted_attributes = attributes.collect do |attribute| - name = attribute["name"] - type = attribute["type"] - [name, type] - end - - header = [status_code, start_time_in_unix_time, elapsed_time] - results = [[count], converted_attributes] - body = [results] - - [header, body] - end - select_responses.first - end end end + +require "droonga/plugin/adapter_select" Added: lib/droonga/plugin/adapter_select.rb (+69 -0) 100644 =================================================================== --- /dev/null +++ lib/droonga/plugin/adapter_select.rb 2013-07-23 14:11:47 +0900 (52a0ade) @@ -0,0 +1,69 @@ +# Copyright (C) 2013 droonga project +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1 as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +module Droonga + class GroongaAdapter + class Select + def select_convert_request(select_request) + table = select_request["table"] + output_columns = select_request["output_columns"] + attributes = output_columns.split(/, */) + + { + "queries" => { + table => { + "source" => table, + "output" => { + "elements" => [ + "startTime", + "elapsedTime", + "count", + "attributes", + "records", + ], + "attributes" => attributes, + }, + } + } + } + end + + def select_convert_response(search_response) + select_responses = search_response.collect do |key, value| + status_code = 0 + + start_time = value["startTime"] + start_time_in_unix_time = Time.parse(start_time).to_f + elapsed_time = value["elapsedTime"] + count = value["count"] + + attributes = value["attributes"] + converted_attributes = attributes.collect do |attribute| + name = attribute["name"] + type = attribute["type"] + [name, type] + end + + header = [status_code, start_time_in_unix_time, elapsed_time] + results = [[count], converted_attributes] + body = [results] + + [header, body] + end + select_responses.first + end + end + end +end Modified: test/plugin/adapter/groonga/test_select.rb (+2 -3) =================================================================== --- test/plugin/adapter/groonga/test_select.rb 2013-07-23 14:00:40 +0900 (78b0ed1) +++ test/plugin/adapter/groonga/test_select.rb 2013-07-23 14:11:47 +0900 (885747d) @@ -13,12 +13,11 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -require "droonga/plugin/adapter_groonga" +require "droonga/plugin/adapter_select" class AdapterGroongaSelectTest < Test::Unit::TestCase def setup - @proxy = Object.new - @groonga_adapter = Droonga::GroongaAdapter.new(@proxy) + @groonga_adapter = Droonga::GroongaAdapter::Select.new end class RequestTest < self -------------- next part -------------- HTML����������������������������... Download