[Groonga-commit] droonga/fluent-plugin-droonga at bbfcb69 [master] Return Groonga comptilbe result by column_create

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Nov 26 19:11:15 JST 2013


YUKI Hiroshi	2013-11-26 19:11:15 +0900 (Tue, 26 Nov 2013)

  New Revision: bbfcb69d8c46df372b0807bfa2696edd237874da
  https://github.com/droonga/fluent-plugin-droonga/commit/bbfcb69d8c46df372b0807bfa2696edd237874da

  Message:
    Return Groonga comptilbe result by column_create

  Modified files:
    lib/droonga/plugin/handler/groonga.rb
    lib/droonga/plugin/handler/groonga/column_create.rb
    lib/droonga/plugin/handler/groonga/table_create.rb

  Modified: lib/droonga/plugin/handler/groonga.rb (+32 -0)
===================================================================
--- lib/droonga/plugin/handler/groonga.rb    2013-11-26 18:30:00 +0900 (a8d821f)
+++ lib/droonga/plugin/handler/groonga.rb    2013-11-26 19:11:15 +0900 (5db4ede)
@@ -45,6 +45,38 @@ module Droonga
       SUCCESS          = 0
       INVALID_ARGUMENT = -22
     end
+
+    class Command
+      class CommandError < StandardError
+        attr_reader :status, :message, :result
+
+        def initialize(params={})
+          @status = params[:status]
+          @message = params[:message]
+          @result = params[:result]
+        end
+      end
+
+      def initialize(context)
+        @context = context
+      end
+
+      def execute(request)
+        @start_time = Time.now.to_f
+        result = process_request(request)
+        [header(Status::SUCCESS), result]
+      rescue CommandError => error
+        [header(error.status, error.message), error.result]
+      end
+
+      private
+      def header(return_code, error_message="")
+        elapsed_time = Time.now.to_f - @start_time
+        header = [return_code, @start_time, elapsed_time]
+        header.push(error_message) unless error_message.empty?
+        header
+      end
+    end
   end
 end
 

  Modified: lib/droonga/plugin/handler/groonga/column_create.rb (+4 -8)
===================================================================
--- lib/droonga/plugin/handler/groonga/column_create.rb    2013-11-26 18:30:00 +0900 (7534617)
+++ lib/droonga/plugin/handler/groonga/column_create.rb    2013-11-26 19:11:15 +0900 (de6e79a)
@@ -20,12 +20,8 @@ require "groonga/command/column-create"
 
 module Droonga
   class GroongaHandler
-    class ColumnCreate
-      def initialize(context)
-        @context = context
-      end
-
-      def execute(request)
+    class ColumnCreate < Command
+      def process_request(request)
         command_class = Groonga::Command.find("column_create")
         @command = command_class.new("column_create", request)
 
@@ -48,7 +44,7 @@ module Droonga
             table.column(column_name, column_type, options)
           end
         end
-        [true]
+        true
       end
 
       def create_column_options
@@ -78,7 +74,7 @@ module Droonga
             table.index("#{target_table}.#{target_column}", options)
           end
         end
-        [true]
+        true
       end
 
       def create_index_options

  Modified: lib/droonga/plugin/handler/groonga/table_create.rb (+8 -17)
===================================================================
--- lib/droonga/plugin/handler/groonga/table_create.rb    2013-11-26 18:30:00 +0900 (a5ddeef)
+++ lib/droonga/plugin/handler/groonga/table_create.rb    2013-11-26 19:11:15 +0900 (6b69330)
@@ -20,32 +20,23 @@ require "groonga/command/table-create"
 
 module Droonga
   class GroongaHandler
-    class TableCreate
-      def initialize(context)
-        @context = context
-      end
-
-      def header(return_code, error_message="")
-        elapsed_time = Time.now.to_f - @start_time
-        header = [return_code, @start_time, elapsed_time]
-        header.push(error_message) unless error_message.empty?
-        header
-      end
-
-      def execute(request)
-        @start_time = Time.now.to_f
-
+    class TableCreate < Command
+      def process_request(request)
         command_class = Groonga::Command.find("table_create")
         @command = command_class.new("table_create", request)
 
         name = @command["name"]
-        return [header(Status::INVALID_ARGUMENT, "Should not create anonymous table"), false] unless name
+        unless name
+          raise CommandError.new(:status => Status::INVALID_ARGUMENT,
+                                 :message => "Should not create anonymous table",
+                                 :result => false)
+        end
 
         options = parse_command
         Groonga::Schema.define(:context => @context) do |schema|
           schema.create_table(name, options)
         end
-        [header(Status::SUCCESS), true]
+        true
       end
 
       private
-------------- next part --------------
HTML����������������������������...
Download 



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