Kouhei Sutou
null+****@clear*****
Sat Mar 15 19:30:11 JST 2014
Kouhei Sutou 2014-03-15 19:30:11 +0900 (Sat, 15 Mar 2014) New Revision: 01c406151c3f70e08b15efb2aa7313ffef871d80 https://github.com/ranguba/gqtp/commit/01c406151c3f70e08b15efb2aa7313ffef871d80 Message: Change directory for backend modules gqtp/connection -> gqtp/backend ^^^^^^^^^^ Because thread and cool.io aren't connection. Modified files: lib/gqtp/client.rb test/test-client.rb Renamed files: lib/gqtp/backend/coolio.rb (from lib/gqtp/connection/coolio.rb) lib/gqtp/backend/synchronous.rb (from lib/gqtp/connection/synchronous.rb) lib/gqtp/backend/thread.rb (from lib/gqtp/connection/thread.rb) Renamed: lib/gqtp/backend/coolio.rb (+2 -2) 97% =================================================================== --- lib/gqtp/connection/coolio.rb 2014-01-07 16:00:53 +0900 (0b45962) +++ lib/gqtp/backend/coolio.rb 2014-03-15 19:30:11 +0900 (32bc4a5) @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2012 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2012-2014 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -19,7 +19,7 @@ require "cool.io" module GQTP - module Connection + module Backend module Coolio class Request def initialize(loop) Renamed: lib/gqtp/backend/synchronous.rb (+2 -2) 97% =================================================================== --- lib/gqtp/connection/synchronous.rb 2014-01-07 16:00:53 +0900 (bb59b30) +++ lib/gqtp/backend/synchronous.rb 2014-03-15 19:30:11 +0900 (d36281c) @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2012 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2012-2014 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -17,7 +17,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA module GQTP - module Connection + module Backend module Synchronous class Request def initialize(data) Renamed: lib/gqtp/backend/thread.rb (+2 -2) 97% =================================================================== --- lib/gqtp/connection/thread.rb 2014-01-07 16:00:53 +0900 (5a728a1) +++ lib/gqtp/backend/thread.rb 2014-03-15 19:30:11 +0900 (18fb3ab) @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2012 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2012-2014 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -20,7 +20,7 @@ require "socket" require "thread" module GQTP - module Connection + module Backend module Thread class Request def initialize(thread) Modified: lib/gqtp/client.rb (+14 -13) =================================================================== --- lib/gqtp/client.rb 2014-01-07 16:00:53 +0900 (0fa66e3) +++ lib/gqtp/client.rb 2014-03-15 19:30:11 +0900 (7f6ef0b) @@ -26,7 +26,7 @@ module GQTP @options = options.dup @options[:host] ||= @options[:address] || "127.0.0.1" @options[:port] ||= 10043 - @connection = create_connection + @backend = create_backend end def send(body, options={}, &block) @@ -35,13 +35,13 @@ module GQTP if block_given? sequential_request = SequentialRequest.new - write_request =****@conne*****(header.pack, body) do + write_request =****@backe*****(header.pack, body) do sequential_request << read(&block) end sequential_request << write_request sequential_request else - @connection.write(header.pack, body) + @backend.write(header.pack, body) end end @@ -51,9 +51,9 @@ module GQTP response_body = nil sequential_request = SequentialRequest.new - read_header_request =****@conne*****(Header.size) do |header| + read_header_request =****@backe*****(Header.size) do |header| parser << header - read_body_request =****@conne*****(parser.header.size) do |body| + read_body_request =****@backe*****(parser.header.size) do |body| response_body = body yield(parser.header, response_body) if block_given? end @@ -88,7 +88,7 @@ module GQTP sync = !block_given? sequential_request = SequentialRequest.new quit_request = send("quit", :header => header_for_close) do - @connection.close + @backend.close yield if block_given? end sequential_request << quit_request @@ -102,18 +102,19 @@ module GQTP end private - def create_connection - connection = @options[:connection] || :thread + def create_backend + # :connection is just for backward compatibility. + backend = @options[:backend] || @options[:connection] || :thread begin - require "gqtp/connection/#{connection}" + require "gqtp/backend/#{backend}" rescue LoadError - raise ArgumentError, "unknown connection: <#{connection.inspect}>" + raise ArgumentError, "unknown backend: <#{backend.inspect}>: #{$!}" end - module_name = connection.to_s.capitalize - connection_module = GQTP::Connection.const_get(module_name) - connection_module::Client.new(@options) + module_name = backend.to_s.capitalize + backend_module = GQTP::Backend.const_get(module_name) + backend_module::Client.new(@options) end def header_for_close Modified: test/test-client.rb (+6 -4) =================================================================== --- test/test-client.rb 2014-01-07 16:00:53 +0900 (eea06e8) +++ test/test-client.rb 2014-03-15 19:30:11 +0900 (56b42c8) @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2012-2013 Kouhei Sutou <kou �� clear-code.com> +# Copyright (C) 2012-2014 Kouhei Sutou <kou �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -21,10 +21,12 @@ require "socket" require "gqtp/client" class ClientTest < Test::Unit::TestCase - class CreateConnectionTest < self + class CreateBackendTest < self def test_unknown - assert_raise(ArgumentError.new("unknown connection: <\"unknown\">")) do - GQTP::Client.new(:connection => "unknown") + message = "unknown backend: <\"unknown\">: " + + "cannot load such file -- gqtp/backend/unknown" + assert_raise(ArgumentError.new(message)) do + GQTP::Client.new(:backend => "unknown") end end -------------- next part -------------- HTML����������������������������...Download