From 4b171163578ad526c5ed071f51cef90872c0f359 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 18 Jul 2024 00:45:42 +0900 Subject: [PATCH] Avoid globally polluting ::String class --- lib/bullet/detector/unused_eager_loading.rb | 2 ++ lib/bullet/ext/string.rb | 12 +++++++++--- lib/bullet/registry/object.rb | 2 ++ spec/bullet/ext/string_spec.rb | 2 ++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/bullet/detector/unused_eager_loading.rb b/lib/bullet/detector/unused_eager_loading.rb index d9bc2af7..c693a6c5 100644 --- a/lib/bullet/detector/unused_eager_loading.rb +++ b/lib/bullet/detector/unused_eager_loading.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +using Bullet::Ext::String + module Bullet module Detector class UnusedEagerLoading < Association diff --git a/lib/bullet/ext/string.rb b/lib/bullet/ext/string.rb index 96f02c66..1b9e9413 100644 --- a/lib/bullet/ext/string.rb +++ b/lib/bullet/ext/string.rb @@ -1,7 +1,13 @@ # frozen_string_literal: true -class String - def bullet_class_name - sub(/:[^:]*?$/, '') +module Bullet + module Ext + module String + refine ::String do + def bullet_class_name + sub(/:[^:]*?$/, '') + end + end + end end end diff --git a/lib/bullet/registry/object.rb b/lib/bullet/registry/object.rb index 1eda349e..25f02c6d 100644 --- a/lib/bullet/registry/object.rb +++ b/lib/bullet/registry/object.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +using Bullet::Ext::String + module Bullet module Registry class Object < Base diff --git a/spec/bullet/ext/string_spec.rb b/spec/bullet/ext/string_spec.rb index d8add1f9..25894ab9 100644 --- a/spec/bullet/ext/string_spec.rb +++ b/spec/bullet/ext/string_spec.rb @@ -2,6 +2,8 @@ require 'spec_helper' +using Bullet::Ext::String + describe String do context 'bullet_class_name' do it 'should only return class name' do