Skip to content

Commit

Permalink
Avoid globally polluting ::String class
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Aug 10, 2024
1 parent 1ef0ee1 commit 4b17116
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/bullet/detector/unused_eager_loading.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

using Bullet::Ext::String

module Bullet
module Detector
class UnusedEagerLoading < Association
Expand Down
12 changes: 9 additions & 3 deletions lib/bullet/ext/string.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions lib/bullet/registry/object.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

using Bullet::Ext::String

module Bullet
module Registry
class Object < Base
Expand Down
2 changes: 2 additions & 0 deletions spec/bullet/ext/string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4b17116

Please sign in to comment.