Skip to content

Commit

Permalink
Make any_not_empty? extension support passing pattern argument to any?
Browse files Browse the repository at this point in the history
Passing an argument is supported since Ruby 2.5.
  • Loading branch information
jeremyevans committed Nov 20, 2023
1 parent 9099201 commit e728617
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== master

* Make any_not_empty? extension support passing pattern argument to any? (jeremyevans) (#2100)

* Respect :skip_transaction option in PostgreSQL Dataset#paged_each (jeremyevans) (#2097)

* Add TimestampMigrator.run_single to run a single migration file up or down (opya, jeremyevans) (#2093)
Expand Down
4 changes: 2 additions & 2 deletions lib/sequel/extensions/any_not_empty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
module Sequel
module AnyNotEmpty
# If a block is not given, return whether the dataset is not empty.
def any?
if defined?(yield)
def any?(*a)
if !a.empty? || defined?(yield)
super
else
!empty?
Expand Down
9 changes: 9 additions & 0 deletions spec/extensions/any_not_empty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@
@ds.with_fetch([]).any?{|x| x[:one] == 1}.must_equal false
@ds.db.sqls.must_equal ["SELECT * FROM t"]
end

it "should use default behavior if argument is given" do
@ds.with_fetch(:one=>1).any?(Hash).must_equal true
@ds.db.sqls.must_equal ["SELECT * FROM t"]
@ds.with_fetch(:one=>1).any?(Array).must_equal false
@ds.db.sqls.must_equal ["SELECT * FROM t"]
@ds.with_fetch([]).any?(Hash).must_equal false
@ds.db.sqls.must_equal ["SELECT * FROM t"]
end if RUBY_VERSION >= '2.5'
end

0 comments on commit e728617

Please sign in to comment.