[Groonga-commit] droonga/fluent-plugin-droonga at 11c21e8 [master] Simply command apply pattern

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Feb 3 12:18:20 JST 2014


Kouhei Sutou	2014-02-03 12:18:20 +0900 (Mon, 03 Feb 2014)

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

  Message:
    Simply command apply pattern
    
    It is changed to a pattern from an array of patterns. Maybe, an array
    of patterns is needless.

  Modified files:
    lib/droonga/command.rb
    lib/droonga/plugin/output_adapter/crud.rb
    lib/droonga/plugin/output_adapter/groonga.rb
    lib/droonga/plugin_registerable.rb
    test/unit/test_command.rb
    test/unit/test_command_repository.rb

  Modified: lib/droonga/command.rb (+7 -13)
===================================================================
--- lib/droonga/command.rb    2014-01-31 19:24:17 +0900 (19d1547)
+++ lib/droonga/command.rb    2014-02-03 12:18:20 +0900 (9933f78)
@@ -18,13 +18,12 @@ module Droonga
     attr_reader :method_name
     #
     #
-    # @option options [Array<Array>] :patterns The patterns to be matched
-    #    against message. If all of the patterns are matched to a message,
+    # @option options [Array] :pattern The pattern to be matched
+    #    against message. If the pattern is matched to a message,
     #    the command will be applied.
     #
-    #    Here is patterns syntax.
+    #    Here is pattern syntax.
     #
-    #      * PATTERNS = [PATTERN*]
     #      * PATTERN = [TARGET_PATH, OPERATOR, ARGUMENTS*]
     #      * PATTERN = [PATTERN, LOGICAL_OPERATOR, PATTERN]
     #      * TARGET_PATH = "COMPONENT(.COMPONENT)*"
@@ -37,7 +36,7 @@ module Droonga
     #    For example:
     #
     #    ```
-    #    [["type", :equal, "search"]]
+    #    ["type", :equal, "search"]
     #    ```
     #
     #    matches to the following message:
@@ -49,7 +48,7 @@ module Droonga
     #    Another example:
     #
     #    ```
-    #    [["body.output.limit", :equal, 10]]
+    #    ["body.output.limit", :equal, 10]
     #    ```
     #
     #    matches to the following message:
@@ -69,17 +68,12 @@ module Droonga
     end
 
     def match?(message)
-      patterns.all? do |pattern|
-        match_pattern?(pattern, message)
-      end
+      match_pattern?(@options[:pattern], message)
     end
 
     private
-    def patterns
-      @options[:patterns] || []
-    end
-
     def match_pattern?(pattern, message)
+      return false if pattern.nil?
       path, operator, *arguments = pattern
       target = resolve_path(path, message)
       apply_operator(operator, target, arguments)

  Modified: lib/droonga/plugin/output_adapter/crud.rb (+1 -1)
===================================================================
--- lib/droonga/plugin/output_adapter/crud.rb    2014-01-31 19:24:17 +0900 (aee59a8)
+++ lib/droonga/plugin/output_adapter/crud.rb    2014-02-03 12:18:20 +0900 (0a29886)
@@ -20,7 +20,7 @@ module Droonga
     repository.register("crud", self)
 
     command :convert_success,
-            :patterns => [["replyTo.type", :equal, "add.result"]]
+            :pattern => ["replyTo.type", :equal, "add.result"]
     def convert_success(output_message)
       if output_message.body.include?("success")
         success = output_message.body["success"]

  Modified: lib/droonga/plugin/output_adapter/groonga.rb (+2 -2)
===================================================================
--- lib/droonga/plugin/output_adapter/groonga.rb    2014-01-31 19:24:17 +0900 (ebf28f7)
+++ lib/droonga/plugin/output_adapter/groonga.rb    2014-02-03 12:18:20 +0900 (6bd2349)
@@ -20,7 +20,7 @@ module Droonga
     repository.register("groonga", self)
 
     command :convert_select,
-            :patterns => [["originalTypes", :include?, "select"]]
+            :pattern => ["originalTypes", :include?, "select"]
     def convert_select(output_message)
       command = Select.new
       output_message.body = command.convert(output_message.body)
@@ -32,7 +32,7 @@ module Droonga
       "column_create.result",
     ]
     command :convert_generic_result,
-            :patterns => [["replyTo.type", :in, *groonga_results]]
+            :pattern => ["replyTo.type", :in, *groonga_results]
     def convert_generic_result(output_message)
       if output_message.body.include?("result")
         output_message.body = output_message.body["result"]

  Modified: lib/droonga/plugin_registerable.rb (+1 -6)
===================================================================
--- lib/droonga/plugin_registerable.rb    2014-01-31 19:24:17 +0900 (3b2f210)
+++ lib/droonga/plugin_registerable.rb    2014-02-03 12:18:20 +0900 (210953c)
@@ -41,15 +41,10 @@ module Droonga
     def command(method_name_or_map, options={})
       if method_name_or_map.is_a?(Hash)
         type, method_name = method_name_or_map.to_a.first
-        options[:patterns] ||= []
-        options[:patterns] << ["type", :equal, type.to_s]
       else
         method_name = method_name_or_map
-        if options.empty?
-          options[:patterns] ||= []
-          options[:patterns] << ["type", :equal, method_name.to_s]
-        end
       end
+      options[:pattern] ||= ["type", :equal, method_name.to_s]
       command = Command.new(method_name, options)
       @command_repository.register(command)
     end

  Modified: test/unit/test_command.rb (+12 -12)
===================================================================
--- test/unit/test_command.rb    2014-01-31 19:24:17 +0900 (04d0a4a)
+++ test/unit/test_command.rb    2014-02-03 12:18:20 +0900 (0ef703f)
@@ -56,24 +56,24 @@ class CommandTest < Test::Unit::TestCase
   end
 
   class MatchTest < self
-    def command(patterns)
-      super(:method_name, :patterns => patterns)
+    def command(pattern)
+      super(:method_name, :pattern => pattern)
     end
 
-    def match?(patterns, message)
-      command(patterns).match?(message)
+    def match?(pattern, message)
+      command(pattern).match?(message)
     end
 
     class EqualTest < self
       def test_same_value
-        assert_true(match?([["type", :equal, "select"]],
+        assert_true(match?(["type", :equal, "select"],
                            {
                              "type" => "select"
                            }))
       end
 
       def test_different_value
-        assert_false(match?([["type", :equal, "select"]],
+        assert_false(match?(["type", :equal, "select"],
                             {
                               "type" => "search",
                             }))
@@ -82,14 +82,14 @@ class CommandTest < Test::Unit::TestCase
 
     class InTest < self
       def test_exist
-        assert_true(match?([["type", :in, "table_create", "table_remove"]],
+        assert_true(match?(["type", :in, "table_create", "table_remove"],
                            {
                              "type" => "table_remove"
                            }))
       end
 
       def test_not_exist
-        assert_false(match?([["type", :in, "table_create", "table_remove"]],
+        assert_false(match?(["type", :in, "table_create", "table_remove"],
                             {
                               "type" => "column_create",
                             }))
@@ -98,26 +98,26 @@ class CommandTest < Test::Unit::TestCase
 
     class IncludeTest < self
       def test_exist
-        assert_true(match?([["originalTypes", :include?, "select"]],
+        assert_true(match?(["originalTypes", :include?, "select"],
                            {
                              "originalTypes" => ["search", "select"],
                            }))
       end
 
       def test_not_exist
-        assert_false(match?([["originalTypes", :include?, "select"]],
+        assert_false(match?(["originalTypes", :include?, "select"],
                             {
                               "originalTypes" => ["load"],
                             }))
       end
 
       def test_no_key
-        assert_false(match?([["originalTypes", :include?, "select"]],
+        assert_false(match?(["originalTypes", :include?, "select"],
                             {}))
       end
 
       def test_not_enumerable
-        assert_false(match?([["originalTypes", :include?, "select"]],
+        assert_false(match?(["originalTypes", :include?, "select"],
                             {
                               "originalTypes" => 29,
                             }))

  Modified: test/unit/test_command_repository.rb (+1 -1)
===================================================================
--- test/unit/test_command_repository.rb    2014-01-31 19:24:17 +0900 (e14113a)
+++ test/unit/test_command_repository.rb    2014-02-03 12:18:20 +0900 (db3d7d8)
@@ -24,7 +24,7 @@ class CommandRepositoryTest < Test::Unit::TestCase
     def setup
       super
       @command = Droonga::Command.new(:select,
-                                      :patterns => [["type", :equal, "select"]])
+                                      :pattern => ["type", :equal, "select"])
       @repository.register(@command)
     end
 
-------------- next part --------------
HTML����������������������������...
Download 



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