Skip to content

Commit 6ec4ada

Browse files
authored
RCBC-490: Raise Error::InvalidArgument for invalid search queries (#145)
* RCBC-490: Raise Error::InvalidArgument for invalid search queries * Rubocop fixes
1 parent d2a3ed2 commit 6ec4ada

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

lib/couchbase/collection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def get_multi(ids, options = Options::GetMulti::DEFAULT)
136136
# @return [GetResult]
137137
def get_and_lock(id, lock_time, options = Options::GetAndLock::DEFAULT)
138138
resp = @backend.document_get_and_lock(bucket_name, @scope_name, @name, id,
139-
lock_time.respond_to?(:in_seconds) ? lock_time.public_send(:in_seconds) : lock_time,
139+
lock_time.respond_to?(:in_seconds) ? lock_time.in_seconds : lock_time,
140140
options.to_backend)
141141
GetResult.new do |res|
142142
res.transcoder = options.transcoder

lib/couchbase/protostellar/request_generator/kv.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def get_and_lock_request(id, lock_time, options)
110110
proto_req = Generated::KV::V1::GetAndLockRequest.new(
111111
**location,
112112
key: id,
113-
lock_time: lock_time.respond_to?(:in_seconds) ? lock_time.public_send(:in_seconds) : lock_time
113+
lock_time: lock_time.respond_to?(:in_seconds) ? lock_time.in_seconds : lock_time
114114
)
115115

116116
create_kv_request(proto_req, :get_and_lock, options)

lib/couchbase/search_options.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def initialize
406406

407407
# @return [Hash<Symbol, #to_json>]
408408
def to_h
409-
raise ArgumentError, "either start_time or end_time must be set for DateRangeQuery" if @start_time.nil? && @end_time.nil?
409+
raise Error::InvalidArgument, "either start_time or end_time must be set for DateRangeQuery" if @start_time.nil? && @end_time.nil?
410410

411411
data = {}
412412
data[:boost] = boost if boost
@@ -483,7 +483,7 @@ def initialize
483483

484484
# @return [Hash<Symbol, #to_json>]
485485
def to_h
486-
raise ArgumentError, "either min or max must be set for NumericRangeQuery" if @min.nil? && @max.nil?
486+
raise Error::InvalidArgument, "either min or max must be set for NumericRangeQuery" if @min.nil? && @max.nil?
487487

488488
data = {}
489489
data[:boost] = boost if boost
@@ -551,7 +551,7 @@ def initialize
551551

552552
# @return [Hash<Symbol, #to_json>]
553553
def to_h
554-
raise ArgumentError, "either min or max must be set for TermRangeQuery" if @min.nil? && @max.nil?
554+
raise Error::InvalidArgument, "either min or max must be set for TermRangeQuery" if @min.nil? && @max.nil?
555555

556556
data = {}
557557
data[:boost] = boost if boost
@@ -754,7 +754,7 @@ def empty?
754754

755755
# @return [Hash<Symbol, #to_json>]
756756
def to_h
757-
raise ArgumentError, "compound conjunction query must have sub-queries" if @queries.nil? || @queries.empty?
757+
raise Error::InvalidArgument, "compound conjunction query must have sub-queries" if @queries.nil? || @queries.empty?
758758

759759
data = {:conjuncts => @queries.uniq.map(&:to_h)}
760760
data[:boost] = boost if boost
@@ -799,11 +799,11 @@ def empty?
799799

800800
# @return [Hash<Symbol, #to_json>]
801801
def to_h
802-
raise ArgumentError, "compound disjunction query must have sub-queries" if @queries.nil? || @queries.empty?
802+
raise Error::InvalidArgument, "compound disjunction query must have sub-queries" if @queries.nil? || @queries.empty?
803803

804804
data = {:disjuncts => @queries.uniq.map(&:to_h)}
805805
if min
806-
raise ArgumentError, "disjunction query has fewer sub-queries than configured minimum" if @queries.size < min
806+
raise Error::InvalidArgument, "disjunction query has fewer sub-queries than configured minimum" if @queries.size < min
807807

808808
data[:min] = min
809809
end
@@ -828,7 +828,7 @@ class BooleanQuery < SearchQuery
828828

829829
# @yieldparam [BooleanQuery] self
830830
def initialize
831-
super()
831+
super
832832
@must = ConjunctionQuery.new
833833
@must_not = DisjunctionQuery.new
834834
@should = DisjunctionQuery.new
@@ -861,7 +861,10 @@ def should(*queries)
861861

862862
# @return [Hash<Symbol, #to_json>]
863863
def to_h
864-
raise ArgumentError, "BooleanQuery must have at least one non-empty sub-query" if @must.empty? && @must_not.empty? && @should.empty?
864+
if @must.empty? && @must_not.empty? && @should.empty?
865+
raise Error::InvalidArgument,
866+
"BooleanQuery must have at least one non-empty sub-query"
867+
end
865868

866869
data = {}
867870
data[:must] = @must.to_h unless @must.empty?
@@ -1007,7 +1010,7 @@ def self.match_all(&block)
10071010
class MatchAllQuery < SearchQuery
10081011
# @yieldparam [MatchAllQuery] self
10091012
def initialize
1010-
super()
1013+
super
10111014
yield self if block_given?
10121015
end
10131016

@@ -1030,7 +1033,7 @@ def self.match_none(&block)
10301033
class MatchNoneQuery < SearchQuery
10311034
# @yieldparam [MatchNoneQuery] self
10321035
def initialize
1033-
super()
1036+
super
10341037
yield self if block_given?
10351038
end
10361039

lib/couchbase/utils/time.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def extract_duration(number_or_duration)
5959
return number_or_duration if number_or_duration.class == Integer # rubocop:disable Style/ClassEqualityComparison avoid overrides of #is_a?, #kind_of?
6060

6161
if number_or_duration.respond_to?(:in_milliseconds)
62-
number_or_duration.public_send(:in_milliseconds)
62+
number_or_duration.in_milliseconds
6363
else
6464
number_or_duration
6565
end.to_i

0 commit comments

Comments
 (0)