Skip to content

Commit

Permalink
Merge pull request #3434 from jdufresne/perf
Browse files Browse the repository at this point in the history
Enable rubocop-performance
  • Loading branch information
mshibuya committed Nov 30, 2021
2 parents 62ea5d2 + 737fd15 commit c7f907c
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-performance

AllCops:
Exclude:
- "gemfiles/*"
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def build_statement_for_enum
end

def build_statement_for_uuid
column_for_value(@value) if @value.to_s =~ /\A[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\z/
column_for_value(@value) if /\A[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\z/.match?(@value.to_s)
end

def ar_adapter
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/adapters/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def all(options = {}, scope = nil)
scope = sort_by(options, scope) if options[:sort]
scope
rescue NoMethodError => e
if e.message =~ /page/
if /page/.match?(e.message)
e = e.exception <<-EOM.gsub(/^\s{12}/, '')
#{e.message}
If you don't have kaminari-mongoid installed, add `gem 'kaminari-mongoid'` to your Gemfile.
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def initialize!
# Evaluate the given block either immediately or lazily, based on initialization status.
def apply(&block)
if @initialized
block.call(self)
yield(self)
else
@deferred_blocks << block
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config/fields/types/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Color < StringLike

register_instance_option :color do
if value.present?
if value =~ /^[0-9a-fA-F]{3,6}$/
if /^[0-9a-fA-F]{3,6}$/.match?(value)
"##{value}"
else
value
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/active_record/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Player < ActiveRecord::Base
validates_numericality_of(:number, only_integer: true)
validates_uniqueness_of(:number, scope: :team_id, message: 'There is already a player with that number on this team')
validates_each :name do |record, _attr, value|
record.errors.add(:base, 'Player is cheating') if value.to_s =~ /on steroids/
record.errors.add(:base, 'Player is cheating') if /on steroids/.match?(value.to_s)
end

enum formation: {start: 'start', substitute: 'substitute'}
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy_app/app/mongoid/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Player
validates_uniqueness_of(:number, scope: :team_id, message: 'There is already a player with that number on this team')

validates_each :name do |record, _attr, value|
record.errors.add(:base, 'Player is cheating') if value.to_s =~ /on steroids/
record.errors.add(:base, 'Player is cheating') if /on steroids/.match?(value.to_s)
end

has_one :draft, dependent: :destroy
Expand Down
2 changes: 1 addition & 1 deletion spec/orm/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def silence_stream(stream)
old_stream = stream.dup
stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
stream.reopen(/mswin|mingw/.match?(RbConfig::CONFIG['host_os']) ? 'NUL:' : '/dev/null')
stream.sync = true
yield
ensure
Expand Down
4 changes: 2 additions & 2 deletions spec/rails_admin/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

it 'triggers RailsAdmin config to be reloaded' do
# this simulates rails code reloading
RailsAdmin::Engine.initializers.select do |i|
RailsAdmin::Engine.initializers.find do |i|
i.name == 'RailsAdmin reload config in development'
end.first.block.call(Rails.application)
end.block.call(Rails.application)
Rails.application.executor.wrap do
ActiveSupport::Reloader.new.tap(&:class_unload!).complete!
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/cuprite_logger.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ConsoleLogger
def self.puts(message)
warn(message) unless message.start_with?(' ◀') || message.start_with?("\n\n▶")
warn(message) unless message.start_with?(' ◀', "\n\n▶")
end
end

0 comments on commit c7f907c

Please sign in to comment.