Skip to content

Commit e83a160

Browse files
committed
Add JSONAPI::CompatibilityHelper module for version-safe deprecation warnings
1 parent ff8bc72 commit e83a160

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
# JSONAPI::CompatibilityHelper
4+
#
5+
# This module provides a version-safe method for issuing deprecation warnings
6+
# that works across multiple versions of Rails (7.x, 8.x, etc).
7+
#
8+
# Usage:
9+
# JSONAPI::CompatibilityHelper.deprecation_warn("Your deprecation message")
10+
#
11+
# The method will use the public `warn` method if available, otherwise it will
12+
# use `send(:warn, ...)` to maintain compatibility with Rails 8+ where `warn`
13+
# is private.
14+
#
15+
# Example:
16+
# JSONAPI::CompatibilityHelper.deprecation_warn("This feature is deprecated.")
17+
18+
module JSONAPI
19+
module CompatibilityHelper
20+
def deprecation_warn(message)
21+
if ActiveSupport::Deprecation.respond_to?(:warn) && ActiveSupport::Deprecation.public_method_defined?(:warn)
22+
ActiveSupport::Deprecation.warn(message)
23+
else
24+
ActiveSupport::Deprecation.send(:warn, message)
25+
end
26+
end
27+
module_function :deprecation_warn
28+
end
29+
end

0 commit comments

Comments
 (0)