[Groonga-commit] groonga/fluent-plugin-droonga at 7908121 [master] Add "column_create" command

Back to archive index

Kosuke Asami null+****@clear*****
Tue Jul 16 12:53:52 JST 2013


Kosuke Asami	2013-07-16 12:53:52 +0900 (Tue, 16 Jul 2013)

  New Revision: 79081214788890936c65be92bfeac86fd8a6fc5f
  https://github.com/groonga/fluent-plugin-droonga/commit/79081214788890936c65be92bfeac86fd8a6fc5f

  Message:
    Add "column_create" command

  Copied files:
    lib/droonga/plugin/groonga/column_create.rb
      (from lib/droonga/plugin/handler_groonga.rb)
    test/plugin/groonga/test_column_create.rb
      (from lib/droonga/plugin/handler_groonga.rb)
  Modified files:
    lib/droonga/plugin/handler_groonga.rb

  Copied: lib/droonga/plugin/groonga/column_create.rb (+19 -15) 54%
===================================================================
--- lib/droonga/plugin/handler_groonga.rb    2013-07-15 15:37:50 +0900 (66308a7)
+++ lib/droonga/plugin/groonga/column_create.rb    2013-07-16 12:53:52 +0900 (0bde8ed)
@@ -16,25 +16,29 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 require "groonga"
-
-require "droonga/handler"
+require "groonga/command/column-create"
 
 module Droonga
-  class GroongaHandler < Droonga::Handler
-    Droonga::HandlerPlugin.register("groonga", self)
+  class GroongaHandler
+    class ColumnCreate
+      def initialize(context)
+        @context = context
+      end
 
-    command :table_create
-    def table_create(request)
-      command = TableCreate.new(@context)
-      outputs = command.execute(request)
-      post(outputs)
-    end
+      def execute(request)
+        command_class = Groonga::Command.find("column_create")
+        @command = command_class.new("column_create", request)
 
-    module Status
-      SUCCESS          = 0
-      INVALID_ARGUMENT = -22
+        table_name = @command["table"]
+        column_name = @command["name"]
+        column_type = @command["type"]
+        Groonga::Schema.define(:context => @context) do |schema|
+          schema.change_table(table_name) do |table|
+            table.column(column_name, column_type)
+          end
+        end
+        [true]
+      end
     end
   end
 end
-
-require "droonga/plugin/groonga/table_create"

  Modified: lib/droonga/plugin/handler_groonga.rb (+8 -0)
===================================================================
--- lib/droonga/plugin/handler_groonga.rb    2013-07-15 15:37:50 +0900 (66308a7)
+++ lib/droonga/plugin/handler_groonga.rb    2013-07-16 12:53:52 +0900 (d4691b0)
@@ -30,6 +30,13 @@ module Droonga
       post(outputs)
     end
 
+    command :column_create
+    def column_create(request)
+      command = ColumnCreate.new(@context)
+      outputs = command.execute(request)
+      post(outputs)
+    end
+
     module Status
       SUCCESS          = 0
       INVALID_ARGUMENT = -22
@@ -38,3 +45,4 @@ module Droonga
 end
 
 require "droonga/plugin/groonga/table_create"
+require "droonga/plugin/groonga/column_create"

  Copied: test/plugin/groonga/test_column_create.rb (+5 -23) 59%
===================================================================
--- lib/droonga/plugin/handler_groonga.rb    2013-07-15 15:37:50 +0900 (66308a7)
+++ test/plugin/groonga/test_column_create.rb    2013-07-16 12:53:52 +0900 (6ccdcd8)
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-#
 # Copyright (C) 2013 droonga project
 #
 # This library is free software; you can redistribute it and/or
@@ -15,26 +13,10 @@
 # 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 "groonga"
-
-require "droonga/handler"
-
-module Droonga
-  class GroongaHandler < Droonga::Handler
-    Droonga::HandlerPlugin.register("groonga", self)
-
-    command :table_create
-    def table_create(request)
-      command = TableCreate.new(@context)
-      outputs = command.execute(request)
-      post(outputs)
-    end
-
-    module Status
-      SUCCESS          = 0
-      INVALID_ARGUMENT = -22
-    end
+class ColumnCreateTest < GroongaHandlerTest
+  def test_success
+    @handler.table_create({"name" => "Books"})
+    @handler.column_create({"table" => "Books", "name" => "title", "type" => "ShortText"})
+    assert_equal([true], @worker.body)
   end
 end
-
-require "droonga/plugin/groonga/table_create"
-------------- next part --------------
HTML����������������������������...
Download 



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