Skip to content

Commit 0eb11bc

Browse files
committed
Refactor deprecation warnings to use CompatibilityHelper and ensure consistent require statements
1 parent e83a160 commit 0eb11bc

5 files changed

Lines changed: 18 additions & 17 deletions

File tree

lib/jsonapi/acts_as_resource_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
require 'csv'
4-
4+
require_relative 'compatibility_helper'
55
module JSONAPI
66
module ActsAsResourceController
77
MEDIA_TYPE_MATCHER = /.+".+"[^,]*|[^,]+/
@@ -63,16 +63,16 @@ def index_related_resources
6363

6464
def get_related_resource
6565
# :nocov:
66-
ActiveSupport::Deprecation.warn "In #{self.class.name} you exposed a `get_related_resource`"\
67-
" action. Please use `show_related_resource` instead."
66+
JSONAPI::CompatibilityHelper.deprecation_warn("In #{self.class.name} you exposed a `get_related_resource`"\
67+
" action. Please use `show_related_resource` instead.")
6868
show_related_resource
6969
# :nocov:
7070
end
7171

7272
def get_related_resources
7373
# :nocov:
74-
ActiveSupport::Deprecation.warn "In #{self.class.name} you exposed a `get_related_resources`"\
75-
" action. Please use `index_related_resources` instead."
74+
JSONAPI::CompatibilityHelper.deprecation_warn("In #{self.class.name} you exposed a `get_related_resources`"\
75+
" action. Please use `index_related_resources` instead.")
7676
index_related_resources
7777
# :nocov:
7878
end

lib/jsonapi/basic_resource.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'jsonapi/callbacks'
44
require 'jsonapi/configuration'
5-
5+
require_relative 'compatibility_helper'
66
module JSONAPI
77
class BasicResource
88
include Callbacks
@@ -547,7 +547,7 @@ def attribute(attribute_name, options = {})
547547
check_reserved_attribute_name(attr)
548548

549549
if (attr == :id) && (options[:format].nil?)
550-
ActiveSupport::Deprecation.warn('Id without format is no longer supported. Please remove ids from attributes, or specify a format.')
550+
JSONAPI::CompatibilityHelper.deprecation_warn('Id without format is deprecated. Please specify a format for the id attribute.')
551551
end
552552

553553
check_duplicate_attribute_name(attr) if options[:format].nil?
@@ -609,11 +609,12 @@ def has_one(*attrs)
609609
end
610610

611611
def belongs_to(*attrs)
612-
ActiveSupport::Deprecation.warn "In #{name} you exposed a `has_one` relationship "\
612+
613+
JSONAPI::CompatibilityHelper.deprecation_warn( "In #{name} you exposed a `has_one` relationship "\
613614
" using the `belongs_to` class method. We think `has_one`" \
614615
" is more appropriate. If you know what you're doing," \
615616
" and don't want to see this warning again, override the" \
616-
" `belongs_to` class method on your resource."
617+
" `belongs_to` class method on your resource.")
617618
_add_relationship(Relationship::ToOne, *attrs)
618619
end
619620

lib/jsonapi/configuration.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'jsonapi/formatter'
44
require 'jsonapi/processor'
55
require 'concurrent'
6-
6+
require_relative 'compatibility_helper'
77
module JSONAPI
88
class Configuration
99
attr_reader :json_key_format,
@@ -227,7 +227,7 @@ def exception_class_allowed?(e)
227227
end
228228

229229
def default_processor_klass=(default_processor_klass)
230-
ActiveSupport::Deprecation.warn('`default_processor_klass` has been replaced by `default_processor_klass_name`.')
230+
JSONAPI::CompatibilityHelper.deprecation_warn('`default_processor_klass` has been replaced by `default_processor_klass_name`.')
231231
@default_processor_klass = default_processor_klass
232232
end
233233

@@ -241,18 +241,18 @@ def default_processor_klass_name=(default_processor_klass_name)
241241
end
242242

243243
def allow_include=(allow_include)
244-
ActiveSupport::Deprecation.warn('`allow_include` has been replaced by `default_allow_include_to_one` and `default_allow_include_to_many` options.')
244+
JSONAPI::CompatibilityHelper.deprecation_warn('`allow_include` has been replaced by `default_allow_include_to_one` and `default_allow_include_to_many` options.')
245245
@default_allow_include_to_one = allow_include
246246
@default_allow_include_to_many = allow_include
247247
end
248248

249249
def whitelist_all_exceptions=(allow_all_exceptions)
250-
ActiveSupport::Deprecation.warn('`whitelist_all_exceptions` has been replaced by `allow_all_exceptions`')
250+
JSONAPI::CompatibilityHelper.deprecation_warn('`whitelist_all_exceptions` has been replaced by `allow_all_exceptions`')
251251
@allow_all_exceptions = allow_all_exceptions
252252
end
253253

254254
def exception_class_whitelist=(exception_class_allowlist)
255-
ActiveSupport::Deprecation.warn('`exception_class_whitelist` has been replaced by `exception_class_allowlist`')
255+
JSONAPI::CompatibilityHelper.deprecation_warn('`exception_class_whitelist` has been replaced by `exception_class_allowlist`')
256256
@exception_class_allowlist = exception_class_allowlist
257257
end
258258

lib/jsonapi/relationship.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
2-
2+
require_relative 'compatibility_helper'
33
module JSONAPI
44
class Relationship
55
attr_reader :acts_as_set, :foreign_key, :options, :name,
@@ -21,7 +21,7 @@ def initialize(name, options = {})
2121
@polymorphic = options.fetch(:polymorphic, false) == true
2222
@polymorphic_types = options[:polymorphic_types]
2323
if options[:polymorphic_relations]
24-
ActiveSupport::Deprecation.warn('Use polymorphic_types instead of polymorphic_relations')
24+
JSONAPI::CompatibilityHelper.deprecation_warn('Use polymorphic_types instead of polymorphic_relations')
2525
@polymorphic_types ||= options[:polymorphic_relations]
2626
end
2727

lib/jsonapi/resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ module JSONAPI
44
class Resource < ActiveRelationResource
55
root_resource
66
end
7-
end
7+
end

0 commit comments

Comments
 (0)