From d1ffe59ab5fd6e811833c127d43b32e87b5d7131 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sat, 27 Jul 2019 12:56:39 +0900 Subject: Use match? where we don't need MatchData We're already running Performance/RegexpMatch cop, but it seems like the cop is not always =~ justice --- activerecord/lib/active_record/attribute_methods/query.rb | 2 +- .../lib/active_record/connection_adapters/connection_specification.rb | 2 +- activerecord/lib/active_record/explain_subscriber.rb | 2 +- activerecord/lib/arel/visitors/oracle.rb | 2 +- activerecord/test/cases/associations/belongs_to_associations_test.rb | 2 +- activerecord/test/cases/associations/has_one_associations_test.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/attribute_methods/query.rb b/activerecord/lib/active_record/attribute_methods/query.rb index 0cf67644af..5a21e36cc7 100644 --- a/activerecord/lib/active_record/attribute_methods/query.rb +++ b/activerecord/lib/active_record/attribute_methods/query.rb @@ -17,7 +17,7 @@ module ActiveRecord when false, nil then false else if !type_for_attribute(attr_name) { false } - if Numeric === value || value !~ /[^0-9]/ + if Numeric === value || !value.match?(/[^0-9]/) !value.to_i.zero? else return false if ActiveModel::Type::Boolean::FALSE_VALUES.include?(value) diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb index 0732b69f81..20041f0c85 100644 --- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb @@ -275,7 +275,7 @@ module ActiveRecord # hash and merges with the rest of the hash. # Connection details inside of the "url" key win any merge conflicts def resolve_hash_connection(spec) - if spec["url"] && spec["url"] !~ /^jdbc:/ + if spec["url"] && !spec["url"].match?(/^jdbc:/) connection_hash = resolve_url_connection(spec.delete("url")) spec.merge!(connection_hash) end diff --git a/activerecord/lib/active_record/explain_subscriber.rb b/activerecord/lib/active_record/explain_subscriber.rb index a86217abc0..ce209092f5 100644 --- a/activerecord/lib/active_record/explain_subscriber.rb +++ b/activerecord/lib/active_record/explain_subscriber.rb @@ -26,7 +26,7 @@ module ActiveRecord payload[:exception] || payload[:cached] || IGNORED_PAYLOADS.include?(payload[:name]) || - payload[:sql] !~ EXPLAINED_SQLS + !payload[:sql].match?(EXPLAINED_SQLS) end ActiveSupport::Notifications.subscribe("sql.active_record", new) diff --git a/activerecord/lib/arel/visitors/oracle.rb b/activerecord/lib/arel/visitors/oracle.rb index aab66301ef..c54aec71a6 100644 --- a/activerecord/lib/arel/visitors/oracle.rb +++ b/activerecord/lib/arel/visitors/oracle.rb @@ -9,7 +9,7 @@ module Arel # :nodoc: all # if need to select first records without ORDER BY and GROUP BY and without DISTINCT # then can use simple ROWNUM in WHERE clause - if o.limit && o.orders.empty? && o.cores.first.groups.empty? && !o.offset && o.cores.first.set_quantifier.class.to_s !~ /Distinct/ + if o.limit && o.orders.empty? && o.cores.first.groups.empty? && !o.offset && !o.cores.first.set_quantifier.class.to_s.match?(/Distinct/) o.cores.last.wheres.push Nodes::LessThanOrEqual.new( Nodes::SqlLiteral.new("ROWNUM"), o.limit.expr ) diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 3525fa2ab8..21286be320 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -64,7 +64,7 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase Client.find(3).firm ensure sql_log = ActiveRecord::SQLCounter.log - assert sql_log.all? { |sql| /order by/i !~ sql }, "ORDER BY was used in the query: #{sql_log}" + assert sql_log.all? { |sql| !/order by/i.match?(sql) }, "ORDER BY was used in the query: #{sql_log}" end def test_belongs_to_with_primary_key diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 3ef25c7027..9227f10c0e 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -41,7 +41,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase companies(:first_firm).account ensure sql_log = ActiveRecord::SQLCounter.log - assert sql_log.all? { |sql| /order by/i !~ sql }, "ORDER BY was used in the query: #{sql_log}" + assert sql_log.all? { |sql| !/order by/i.match?(sql) }, "ORDER BY was used in the query: #{sql_log}" end def test_has_one_cache_nils -- cgit v1.2.3