Navigation Menu

Skip to content

Commit

Permalink
Fix documents and API arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
komainu8 committed Apr 25, 2017
1 parent 73e4bd0 commit 8cc1385
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
47 changes: 26 additions & 21 deletions lib/groonga/client/request/select.rb
Expand Up @@ -93,20 +93,15 @@ def query(value)
# filter.in_values("tags", "tag1", "tag2")
# # -> --filter 'in_values(tags, "tag1", "tag2")'
#
# @return [Groonga::Client::Request::Select::Filter]
# The new request object for setting a filter condition.
#
# @since 0.4.3
#
# @example: Use between function
# request.
# filter.between("tags", "min", "min_border", "max", "max_border")
# # -> --filter 'between(tags, min, "min_border", max, "max_border")'
# filter.between("tags", 19, "include", 32, "include")
# # -> --filter 'between(tags, 19, "include", 32, "include")'
#
# @return [Groonga::Client::Request::Select::Filter]
# The new request object for setting a filter condition.
#
# @since 0.4.4
# @since 0.4.3
def filter(expression_or_column_name=nil, values_or_value=nil)
if expression_or_column_name.nil? and values_or_value.nil?
return Filter.new(self)
Expand Down Expand Up @@ -195,25 +190,36 @@ def initialize(request)
# Adds a `between` condition then return a new `select`
# request object.
#
# @example: Multiple conditions
# @example: Single condition
# request.
# filter.between("tags", "min", "min_border", "max", "max_border").
# # -> --filter 'between(tags, min, "min_border", max, "max_border")'
#
# @example: Ignore no values case
# @example: Error no values case
# request.
# filter.between("tags")
# # -> --filter ''
# # -> ArgumentError
#
# @param column_name [String, Symbol] The target column name.
#
# @param min [Integer] Specifies the minimal border value of the range.
#
# @param column_name_or_value [String, Symbol, Integer] The target column name
# or target num.
# @param min_border [String] Specifies whether the specified range contains the value
# of min or not.
# If it is "include", min value is include.
# If it is "exclude", min value is not include.
#
# @param values [Object] Range of values.
# @param max [Integer] Specifies the maximum border value of the range.
#
# @param max_border [String] Specifies whether the specified range contains the value
# of max or not.
# If it is "include", max value is include.
# If it is "exclude", max value is not include.
#
# @return [Groonga::Client::Request::Select]
# The new request with the given condition.
def between(column_name_or_value, *values)
parameter = FilterBetweenParameter.new(column_name_or_value, *values)
def between(column_name, min, min_border, max, max_border)
parameter = FilterBetweenParameter.new(column_name, min, min_border, max, max_border)
add_parameter(FilterMerger, parameter)
end

Expand Down Expand Up @@ -495,21 +501,20 @@ def initialize(expression, values)
# @private
class FilterBetweenParameter
include ScriptSyntaxValueEscapable
NUM_OF_ARGUMENTS = 4

def initialize(column_name_or_value, *values)
@column_name_or_value = column_name_or_value
def initialize(column_name, *values)
@column_name = column_name
@values = values
end

def to_parameters
return {} if @values.empty? or @values.length != NUM_OF_ARGUMENTS
return {} if @values.empty?

escaped_values = @values.collect do |value|
escape_script_syntax_value(value)
end
{
filter: "between(#{@column_name_or_value}, #{escaped_values.join(", ")})",
filter: "between(#{@column_name}, #{escaped_values.join(", ")})",
}
end
end
Expand Down
10 changes: 2 additions & 8 deletions test/request/test-select.rb
Expand Up @@ -130,17 +130,11 @@ def between(column_name_or_value, *values)
end

test("no values") do
assert_equal({
:table => "posts",
},
between("tags"))
assert_raise(ArgumentError){ between("tags") }
end

test("too much values") do
assert_equal({
:table => "posts",
},
between("ages", 2, "include", 29, "include", 3))
assert_raise(ArgumentError){ between("ages", 2, "include", 29, "include", 3) }
end
end

Expand Down

0 comments on commit 8cc1385

Please sign in to comment.