forked from JSONAPI-Resources/jsonapi-resources
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcompatibility_helper.rb
More file actions
29 lines (27 loc) · 938 Bytes
/
compatibility_helper.rb
File metadata and controls
29 lines (27 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true
# JSONAPI::CompatibilityHelper
#
# This module provides a version-safe method for issuing deprecation warnings
# that works across multiple versions of Rails (7.x, 8.x, etc).
#
# Usage:
# JSONAPI::CompatibilityHelper.deprecation_warn("Your deprecation message")
#
# The method will use the public `warn` method if available, otherwise it will
# use `send(:warn, ...)` to maintain compatibility with Rails 8+ where `warn`
# is private.
#
# Example:
# JSONAPI::CompatibilityHelper.deprecation_warn("This feature is deprecated.")
module JSONAPI
module CompatibilityHelper
def deprecation_warn(message)
if ActiveSupport::Deprecation.respond_to?(:warn) && ActiveSupport::Deprecation.public_method_defined?(:warn)
ActiveSupport::Deprecation.warn(message)
else
ActiveSupport::Deprecation.send(:warn, message)
end
end
module_function :deprecation_warn
end
end