[Groonga-commit] droonga/fluent-plugin-droonga at 58b935c [master] Add :exist? operator

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Feb 7 11:28:32 JST 2014


Kouhei Sutou	2014-02-07 11:28:32 +0900 (Fri, 07 Feb 2014)

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

  Message:
    Add :exist? operator

  Modified files:
    lib/droonga/command.rb
    test/unit/test_command.rb

  Modified: lib/droonga/command.rb (+5 -3)
===================================================================
--- lib/droonga/command.rb    2014-02-07 11:23:34 +0900 (f238daf)
+++ lib/droonga/command.rb    2014-02-07 11:28:32 +0900 (ef38d77)
@@ -27,9 +27,9 @@ module Droonga
     #      * PATTERN = [TARGET_PATH, OPERATOR, ARGUMENTS*]
     #      * PATTERN = [PATTERN, LOGICAL_OPERATOR, PATTERN]
     #      * TARGET_PATH = "COMPONENT(.COMPONENT)*"
-    #      * OPERATOR = :equal, :in, :include?
+    #      * OPERATOR = :equal, :in, :include?, :exist?
     #                   (More operators may be added in the future.
-    #                    For example, :exist?, :start_with and so on.)
+    #                    For example, :start_with and so on.)
     #      * ARGUMENTS = OBJECT_DEFINED_IN_JSON*
     #      * LOGICAL_OPERATOR = :or (:add will be added.)
     #
@@ -82,7 +82,7 @@ module Droonga
     NONEXISTENT_PATH = Object.new
     def resolve_path(path, message)
       path.split(".").inject(message) do |result, component|
-        return NONEXISTENT_PATH if result.nil?
+        return NONEXISTENT_PATH unless result.is_a?(Hash)
         result[component]
       end
     end
@@ -100,6 +100,8 @@ module Droonga
         arguments.any? do |argument|
           target.include?(argument)
         end
+      when :exist?
+        target != NONEXISTENT_PATH
       else
         raise ArgumentError, "Unknown operator"
       end

  Modified: test/unit/test_command.rb (+18 -0)
===================================================================
--- test/unit/test_command.rb    2014-02-07 11:23:34 +0900 (681ed85)
+++ test/unit/test_command.rb    2014-02-07 11:28:32 +0900 (ab6ad26)
@@ -123,5 +123,23 @@ class CommandTest < Test::Unit::TestCase
                             }))
       end
     end
+
+    class ExistTest < self
+      def test_exist
+        assert_true(match?(["body.result", :exist?],
+                           {
+                             "body" => {
+                               "result" => nil,
+                             },
+                           }))
+      end
+
+      def test_not_exist
+        assert_false(match?(["body.result", :exist?],
+                            {
+                              "body" => nil,
+                            }))
+      end
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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