[Groonga-commit] ranguba/groonga-client at cc82c6e [master] between: make min_border and max_border are optional

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Thu Apr 27 13:27:54 JST 2017


Kouhei Sutou	2017-04-27 13:27:54 +0900 (Thu, 27 Apr 2017)

  New Revision: cc82c6eed8cf9add8ea6d5c55b482914a418cad7
  https://github.com/ranguba/groonga-client/commit/cc82c6eed8cf9add8ea6d5c55b482914a418cad7

  Message:
    between: make min_border and max_border are optional
    
    GitHub: fix #17
    
    Reported by okkez. Thanks!!!

  Modified files:
    lib/groonga/client/request/select.rb
    test/request/select/test-filter.rb

  Modified: lib/groonga/client/request/select.rb (+59 -23)
===================================================================
--- lib/groonga/client/request/select.rb    2017-04-27 11:48:49 +0900 (4c45db6)
+++ lib/groonga/client/request/select.rb    2017-04-27 13:27:54 +0900 (63fa30b)
@@ -199,7 +199,6 @@ module Groonga
           parameters.key?(:offset) and parameters.key?(:limit)
         end
 
-        # @since 0.4.3
         class Filter
           class << self
             # @private
@@ -286,37 +285,72 @@ module Groonga
           # Adds a `between` condition then returns a new `select`
           # request object.
           #
-          # @example Basic usage
-          #    request.
-          #      filter.between(:age, 19, "include", 32, "exclude").
-          #        # -> --filter 'between(age, 19, "include", 32, "exclude")'
-          #
           # @see http://groonga.org/docs/reference/functions/between.html
           #   between function in the Groonga document
           #
-          # @param column_name [String, Symbol] The target column name.
+          # @return [Groonga::Client::Request::Select]
+          #   The new request with the given condition.
+          #
+          # @overload between(column_name, min, max, min_border: "include", max_border: "include")
           #
-          # @param min [Integer] The minimal value of the condition
-          #   range.
+          #   @example Basic usage
+          #      request.
+          #        filter.between(:age, 19, 32)
+          #          # -> --filter 'between(age, 19, "include", 32, "exclude")'
           #
-          # @param min_border ["include", "exclude"] Whether `min` is
-          #    included or not. If `"include"` is specified, `min` is
-          #    included. If `"exclude"` is specified, `min` isn't
-          #    included.
+          #   @!macro [new] between_common
           #
-          # @param max [Integer] The maximum value of the condition
-          #   range.
+          #     @param column_name [Symbol] The target column name.
           #
-          # @param max_border ["include", "exclude"] Whether `max` is
-          #    included or not. If `"include"` is specified, `max` is
-          #    included. If `"exclude"` is specified, `max` isn't
-          #    included.
+          #     @param min [Integer] The minimal value of the
+          #        condition range.
           #
-          # @return [Groonga::Client::Request::Select]
-          #   The new request with the given condition.
+          #     @param max [Integer] The maximum value of the
+          #        condition range.
+          #
+          #     @param min_border ["include", "exclude"] Whether `min` is
+          #        included or not. If `"include"` is specified, `min` is
+          #        included. If `"exclude"` is specified, `min` isn't
+          #        included.
           #
-          # @since 0.4.4
-          def between(column_name, min, min_border, max, max_border)
+          #     @param max_border ["include", "exclude"] Whether `max` is
+          #        included or not. If `"include"` is specified, `max` is
+          #        included. If `"exclude"` is specified, `max` isn't
+          #        included.
+          #
+          #   @macro between_common
+          #
+          #   @since 0.5.0
+          #
+          # @overload between(column_name, min, min_border, max, max_border)
+          #
+          #   @example Basic usage
+          #      request.
+          #        filter.between(:age, 19, "include", 32, "exclude")
+          #          # -> --filter 'between(age, 19, "include", 32, "exclude")'
+          #
+          #   @macro between_common
+          #
+          #   @since 0.4.4
+          def between(*args)
+            n_args = args.size
+            case n_args
+            when 3
+              column_name, min, max = args
+              min_border = "include"
+              max_border = "include"
+            when 4
+              column_name, min, max, options = args
+              min_border = options[:min_border] || "include"
+              max_border = options[:max_border] || "include"
+            when 5
+              column_name, min, min_border, max, max_border = args
+            else
+              message =
+                "wrong number of arguments (given #{n_args}, expected 3..5)"
+              raise ArgumentError, message
+            end
+
             # TODO: Accept not only column name but also literal as
             # the first argument.
             column_name =
@@ -362,6 +396,8 @@ module Groonga
           #
           # @return [Groonga::Client::Request::Select]
           #   The new request with the given condition.
+          #
+          # @since 0.4.3
           def in_values(column_name, *values)
             return @request if values.empty?
 

  Modified: test/request/select/test-filter.rb (+21 -7)
===================================================================
--- test/request/select/test-filter.rb    2017-04-27 11:48:49 +0900 (d8886aa)
+++ test/request/select/test-filter.rb    2017-04-27 13:27:54 +0900 (6e7f3cb)
@@ -233,15 +233,29 @@ title == "[\"He\\ llo\"]"
     end
 
     sub_test_case("#between") do
-      def between(column_name,
-                  min, min_border,
-                  max, max_border)
-        @request.filter.between(column_name,
-                                min, min_border,
-                                max, max_border).to_parameters
+      def between(*args)
+        @request.filter.between(*args).to_parameters
       end
 
-      test("border") do
+      test("min and max") do
+        assert_equal({
+                       :table => "posts",
+                       :filter => "between(ages, 2, \"include\", 29, \"include\")",
+                     },
+                     between(:ages, 2, 29))
+      end
+
+      test("min, max and options") do
+        assert_equal({
+                       :table => "posts",
+                       :filter => "between(ages, 2, \"exclude\", 29, \"exclude\")",
+                     },
+                     between(:ages, 2, 29,
+                             min_border: "exclude",
+                             max_border: "exclude"))
+      end
+
+      test("all") do
         assert_equal({
                        :table => "posts",
                        :filter => "between(ages, 2, \"include\", 29, \"exclude\")",
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index