Skip to content

Commit

Permalink
warn needs to match Kernel's signature (#40)
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
rzane authored Jan 22, 2025
1 parent 3294090 commit 2a01d9d
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
uncruft (0.6.0)
uncruft (0.6.1)
railties (>= 6.1.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
uncruft (0.6.0)
uncruft (0.6.1)
railties (>= 6.1.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
uncruft (0.6.0)
uncruft (0.6.1)
railties (>= 6.1.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
uncruft (0.6.0)
uncruft (0.6.1)
railties (>= 6.1.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7_2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
uncruft (0.6.0)
uncruft (0.6.1)
railties (>= 6.1.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_8_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
uncruft (0.6.0)
uncruft (0.6.1)
railties (>= 6.1.0)

GEM
Expand Down
2 changes: 1 addition & 1 deletion lib/uncruft/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Uncruft
VERSION = '0.6.0'
VERSION = '0.6.1'
end
6 changes: 3 additions & 3 deletions lib/uncruft/warning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module Uncruft
module Warning
DEPRECATION_PATTERN = /(deprecation|deprecated)/i

def warn(str, *args, **kwargs)
def warn(*args, **kwargs)
str = args[0]

if str =~ DEPRECATION_PATTERN # rubocop:disable Performance/RegexpMatch
message = strip_caller_info(str, caller_locations(1..1).first).strip
Uncruft.deprecator.warn(message)
elsif RUBY_VERSION < '2.7' && kwargs.empty?
super(str, *args)
else
super
end
Expand Down
4 changes: 4 additions & 0 deletions spec/uncruft/warning_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@

it "doesn't block generic warnings" do
expect(Uncruft.deprecator).not_to receive(:warn)
warn
warn('oh no, you should worry')
Kernel.warn
Kernel.warn('oh no, you should worry')
Warning.warn('oh no, you should worry')
end

it "accepts kwargs from Kernel.warn" do # rubocop:disable RSpec/NoExpectationExample
warn(uplevel: 1)
warn('oh no, you should worry', uplevel: 1)
Kernel.warn(uplevel: 1)
Kernel.warn('oh no, you should worry', uplevel: 1)
end

Expand Down

0 comments on commit 2a01d9d

Please sign in to comment.