[Groonga-commit] droonga/fluent-plugin-droonga at 839d1dc [master] MessageMatcher: add :start_with operator

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Feb 17 12:12:03 JST 2014


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

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

  Message:
    MessageMatcher: add :start_with operator

  Modified files:
    lib/droonga/message_matcher.rb
    test/unit/test_message_matcher.rb

  Modified: lib/droonga/message_matcher.rb (+7 -2)
===================================================================
--- lib/droonga/message_matcher.rb    2014-02-17 11:30:35 +0900 (fa4907d)
+++ lib/droonga/message_matcher.rb    2014-02-17 12:12:03 +0900 (8072acb)
@@ -21,9 +21,9 @@ module Droonga
   #   * PATTERN = [TARGET_PATH, OPERATOR, ARGUMENTS*]
   #   * PATTERN = [PATTERN, LOGICAL_OPERATOR, PATTERN]
   #   * TARGET_PATH = "COMPONENT(.COMPONENT)*"
-  #   * OPERATOR = :equal, :in, :include?, :exist?
+  #   * OPERATOR = :equal, :in, :include?, :exist?, :start_with
   #                (More operators may be added in the future.
-  #                 For example, :start_with and so on.)
+  #                 For example, :end_with and so on.)
   #   * ARGUMENTS = OBJECT_DEFINED_IN_JSON*
   #   * LOGICAL_OPERATOR = :or (:add will be added.)
   #
@@ -93,6 +93,11 @@ module Droonga
         end
       when :exist?
         target != NONEXISTENT_PATH
+      when :start_with
+        return false unless target.respond_to?(:start_with?)
+        arguments.any? do |argument|
+          target.start_with?(argument)
+        end
       else
         raise ArgumentError, "Unknown operator"
       end

  Modified: test/unit/test_message_matcher.rb (+23 -0)
===================================================================
--- test/unit/test_message_matcher.rb    2014-02-17 11:30:35 +0900 (638927e)
+++ test/unit/test_message_matcher.rb    2014-02-17 12:12:03 +0900 (ab7e8a1)
@@ -133,5 +133,28 @@ class MessageMatcherTest < Test::Unit::TestCase
                             }))
       end
     end
+
+    class StartWithTest < self
+      def test_start_with
+        assert_true(match?(["type", :start_with, "watch."],
+                           {
+                             "type" => "watch.subscribe",
+                           }))
+      end
+
+      def test_not_start_with
+        assert_false(match?(["type", :start_with, "watch."],
+                            {
+                              "type" => "table_create",
+                            }))
+      end
+
+      def test_nil_value
+        assert_false(match?(["type", :start_with, "watch."],
+                            {
+                              "type" => nil,
+                            }))
+      end
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
下載 



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