[Groonga-commit] ranguba/groonga-client at 8db9cc9 [master] Remove needless FilterInValuesParameter

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Thu Apr 27 11:14:40 JST 2017


Kouhei Sutou	2017-04-27 11:14:40 +0900 (Thu, 27 Apr 2017)

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

  Message:
    Remove needless FilterInValuesParameter
    
    in_values("column", ...) is deprecated. Use in_values(:column, ...)
    instead.

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

  Modified: lib/groonga/client/request/select.rb (+24 -27)
===================================================================
--- lib/groonga/client/request/select.rb    2017-04-27 11:04:36 +0900 (9277792)
+++ lib/groonga/client/request/select.rb    2017-04-27 11:14:40 +0900 (1bdc5c2)
@@ -308,25 +308,25 @@ module Groonga
             add_parameter(FilterMerger, parameter)
           end
 
-          # Adds a `in_values` condition then return a new `select`
+          # Adds a `in_values` condition then returns a new `select`
           # request object.
           #
           # @example Multiple conditions
           #    request.
-          #      filter.in_values("tags", "tag1", "tag2").
+          #      filter.in_values(:tags, "tag1", "tag2").
           #        # -> --filter 'in_values(tags, "tag1", "tag2")'
           #      filter("user", "alice")
           #        # -> --filter '(in_values(tags, "tag1", "tag2")) && (user == "alice")'
           #
           # @example Ignore no values case
           #    request.
-          #      filter.in_values("tags")
+          #      filter.in_values(:tags)
           #        # -> --filter ''
           #
           # @see http://groonga.org/docs/reference/functions/in_values.html
           #   `in_values` function in the Groonga document
           #
-          # @param column_name [String, Symbol] The target column name.
+          # @param column_name [Symbol] The target column name.
           #
           # @param values [Object] The column values that cover target
           #   column values.
@@ -334,8 +334,26 @@ module Groonga
           # @return [Groonga::Client::Request::Select]
           #   The new request with the given condition.
           def in_values(column_name, *values)
-            parameter = FilterInValuesParameter.new(column_name, *values)
-            add_parameter(FilterMerger, parameter)
+            return @request if values.empty?
+
+            # TODO: Accept not only column name but also literal as
+            # the first argument.
+            if column_name.is_a?(String)
+              message = "column name (the first argument) "
+              message << "of #{self.class}\##{__method__} "
+              message << "should be Symbol: #{column_name.inspect}: "
+              message << caller(1, 1)[0]
+              warn(message)
+              column_name = column_name.to_sym
+            end
+            expression_values = {column_name: column_name}
+            expression = "in_values(%{column_name}"
+            values.each_with_index do |value, i|
+              expression << ", %{value#{i}}"
+              expression_values[:"value#{i}"] = value
+            end
+            expression << ")"
+            @request.filter(expression, expression_values)
           end
 
           private
@@ -624,27 +642,6 @@ module Groonga
         end
 
         # @private
-        class FilterInValuesParameter
-          include ScriptSyntaxValueEscapable
-
-          def initialize(column_name, *values)
-            @column_name = column_name
-            @values = values
-          end
-
-          def to_parameters
-            return {} if****@value*****?
-
-            escaped_values =****@value***** do |value|
-              escape_script_syntax_value(value)
-            end
-            {
-              filter: "in_values(#{@column_name}, #{escaped_values.join(", ")})",
-            }
-          end
-        end
-
-        # @private
         class OutputColumnsParameter < ValuesParameter
           def initialize(prefix, output_columns)
             super([:"#{prefix}output_columns"], output_columns)

  Modified: test/request/select/test-filter.rb (+3 -3)
===================================================================
--- test/request/select/test-filter.rb    2017-04-27 11:04:36 +0900 (05bfe7d)
+++ test/request/select/test-filter.rb    2017-04-27 11:14:40 +0900 (151c65a)
@@ -270,7 +270,7 @@ title == "[\"He\\ llo\"]"
                        :table => "posts",
                        :filter => "in_values(ages, 2, 29)",
                      },
-                     in_values("ages", 2, 29))
+                     in_values(:ages, 2, 29))
       end
 
       test("strings") do
@@ -278,14 +278,14 @@ title == "[\"He\\ llo\"]"
                        :table => "posts",
                        :filter => "in_values(tags, \"groonga\", \"have \\\"double\\\" quote\")",
                      },
-                     in_values("tags", "groonga", "have \"double\" quote"))
+                     in_values(:tags, "groonga", "have \"double\" quote"))
       end
 
       test("no values") do
         assert_equal({
                        :table => "posts",
                      },
-                     in_values("tags"))
+                     in_values(:tags))
       end
     end
   end
-------------- next part --------------
HTML����������������������������...
Download 



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