Skip to content

Commit 4cb43d9

Browse files
committed
Revert "fix: skip class caching if Rails has it disabled"
This reverts commit 89e69e6.
1 parent 89e69e6 commit 4cb43d9

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

lib/jsonapi/resource_common.rb

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -541,27 +541,19 @@ def rebuild_relationships(relationships)
541541
end
542542

543543
def resource_klass_for(type)
544+
@_resource_type_to_class_cache ||= {}
544545
type = type.underscore
545546

546-
if ::Rails.application.config.cache_classes
547-
@_resource_type_to_class_cache ||= {}
548-
@_resource_type_to_class_cache.fetch(type) do
549-
@_resource_type_to_class_cache[type] = _resource_klass_for(type)
550-
end
551-
else
552-
_resource_klass_for(type)
553-
end
554-
end
555-
556-
def _resource_klass_for(type)
557-
type_with_module = type.start_with?(module_path) ? type : module_path + type
547+
@_resource_type_to_class_cache.fetch(type) do
548+
type_with_module = type.start_with?(module_path) ? type : module_path + type
558549

559-
resource_name = _resource_name_from_type(type_with_module)
560-
resource_klass = resource_name.safe_constantize if resource_name
561-
if resource_klass.nil?
562-
fail NameError, "JSONAPI: Could not find resource '#{type}'. (Class #{resource_name} not found)"
550+
resource_name = _resource_name_from_type(type_with_module)
551+
resource_klass = resource_name.safe_constantize if resource_name
552+
if resource_klass.nil?
553+
fail NameError, "JSONAPI: Could not find resource '#{type}'. (Class #{resource_name} not found)"
554+
end
555+
@_resource_type_to_class_cache[type] = resource_klass
563556
end
564-
resource_klass
565557
end
566558

567559
def resource_klass_for_model(model)

0 commit comments

Comments
 (0)