[Groonga-commit] ranguba/groonga-client at 5b7e5d6 [master] Extract common running code

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Oct 27 18:07:41 JST 2017


Kouhei Sutou	2017-10-27 18:07:41 +0900 (Fri, 27 Oct 2017)

  New Revision: 5b7e5d6434dae59ed93be62cab0ca14a15460c6d
  https://github.com/ranguba/groonga-client/commit/5b7e5d6434dae59ed93be62cab0ca14a15460c6d

  Message:
    Extract common running code

  Added files:
    lib/groonga/client/command-line/runner.rb
  Modified files:
    lib/groonga/client/command-line/groonga-client-index-check.rb
    lib/groonga/client/command-line/groonga-client-index-recreate.rb

  Modified: lib/groonga/client/command-line/groonga-client-index-check.rb (+10 -23)
===================================================================
--- lib/groonga/client/command-line/groonga-client-index-check.rb    2017-10-27 17:58:52 +0900 (c667050)
+++ lib/groonga/client/command-line/groonga-client-index-check.rb    2017-10-27 18:07:41 +0900 (92fbd3e)
@@ -17,6 +17,7 @@
 
 require "groonga/client"
 require "groonga/client/command-line/parser"
+require "groonga/client/command-line/runner"
 
 module Groonga
   class Client
@@ -39,7 +40,7 @@ module Groonga
 
           parser.open_client do |client|
             checker = Checker.new(client, @methods, indexes)
-            checker.check
+            checker.run
           end
         end
 
@@ -67,34 +68,20 @@ module Groonga
           end
         end
 
-        class Checker
+        class Checker < Runner
           def initialize(client, methods, targets)
-            @client = client
+            super(client)
             @methods = methods
             @targets = targets
           end
 
-          def check
-            catch(:fail) do
-              succeeded = true
-              @methods.each do |method|
-                succeeded = false unless __send__("check_#{method}")
-              end
-              succeeded
-            end
-          end
-
-          def abort_run(message)
-            $stderr.puts(message)
-            throw(:fail, false)
-          end
-
-          def execute_command(name, arguments={})
-            response =****@clien*****(name, arguments)
-            unless response.success?
-              abort_run("Failed to run #{name}: #{response.inspect}")
+          private
+          def run_internal
+            succeeded = true
+            @methods.each do |method|
+              succeeded = false unless __send__("check_#{method}")
             end
-            response
+            succeeded
           end
 
           def table_list

  Modified: lib/groonga/client/command-line/groonga-client-index-recreate.rb (+12 -27)
===================================================================
--- lib/groonga/client/command-line/groonga-client-index-recreate.rb    2017-10-27 17:58:52 +0900 (c114562)
+++ lib/groonga/client/command-line/groonga-client-index-recreate.rb    2017-10-27 18:07:41 +0900 (c1661f1)
@@ -18,6 +18,7 @@ require "json"
 
 require "groonga/client"
 require "groonga/client/command-line/parser"
+require "groonga/client/command-line/runner"
 
 module Groonga
   class Client
@@ -36,8 +37,8 @@ module Groonga
           end
 
           parser.open_client do |client|
-            runner = Runner.new(client, @interval, indexes)
-            runner.run do
+            recreator = Recreator.new(client, @interval, indexes)
+            recreator.run do
               @n_workers.times do
                 client.database_unmap
               end
@@ -71,39 +72,23 @@ module Groonga
           end
         end
 
-        class Runner
+        class Recreator < Runner
           def initialize(client, interval, target_indexes)
-            @client = client
+            super(client)
             @interval = interval
             @target_indexes = target_indexes
             @now = Time.now
           end
 
-          def run
-            catch do |tag|
-              @abort_tag = tag
-              alias_column = ensure_alias_column
-              @target_indexes.each do |index|
-                current_index = recreate_index(index, alias_column)
-                remove_old_indexes(index, current_index)
-              end
-              yield if block_given?
-              true
-            end
-          end
-
           private
-          def abort_run(message)
-            $stderr.puts(message)
-            throw(@abort_tag, false)
-          end
-
-          def execute_command(name, arguments={})
-            response =****@clien*****(name, arguments)
-            unless response.success?
-              abort_run("Failed to run #{name}: #{response.inspect}")
+          def run_internal
+            alias_column = ensure_alias_column
+            @target_indexes.each do |index|
+              current_index = recreate_index(index, alias_column)
+              remove_old_indexes(index, current_index)
             end
-            response
+            yield if block_given?
+            true
           end
 
           def config_get(key)

  Added: lib/groonga/client/command-line/runner.rb (+48 -0) 100644
===================================================================
--- /dev/null
+++ lib/groonga/client/command-line/runner.rb    2017-10-27 18:07:41 +0900 (e9e7535)
@@ -0,0 +1,48 @@
+# Copyright (C) 2017  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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+module Groonga
+  class Client
+    module CommandLine
+      class Runner
+        def initialize(client)
+          @client = client
+        end
+
+        def run(&block)
+          catch do |tag|
+            @abort_tag = tag
+            run_internal(&block)
+          end
+        end
+
+        private
+        def abort_run(message)
+          $stderr.puts(message)
+          throw(@abort_tag, false)
+        end
+
+        def execute_command(name, arguments={})
+          response =****@clien*****(name, arguments)
+          unless response.success?
+            abort_run("Failed to run #{name}: #{response.inspect}")
+          end
+          response
+        end
+      end
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171027/6f52308d/attachment-0001.htm 



More information about the Groonga-commit mailing list
Back to archive index