diff --git a/CHANGELOG b/CHANGELOG index dfa16a703..82eddfa9b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) diff --git a/lib/sequel/extensions/any_not_empty.rb b/lib/sequel/extensions/any_not_empty.rb index 87e24051b..0eab81ba5 100644 --- a/lib/sequel/extensions/any_not_empty.rb +++ b/lib/sequel/extensions/any_not_empty.rb @@ -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? diff --git a/spec/extensions/any_not_empty_spec.rb b/spec/extensions/any_not_empty_spec.rb index 4dd1d9974..7ac9e9b69 100644 --- a/spec/extensions/any_not_empty_spec.rb +++ b/spec/extensions/any_not_empty_spec.rb @@ -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