Skip to content

Commit

Permalink
Revert "fix: skip class caching if Rails has it disabled"
Browse files Browse the repository at this point in the history
This reverts commit 89e69e6.
  • Loading branch information
adamkiczula committed Feb 8, 2024
1 parent 89e69e6 commit 4cb43d9
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions lib/jsonapi/resource_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -541,27 +541,19 @@ def rebuild_relationships(relationships)
end

def resource_klass_for(type)
@_resource_type_to_class_cache ||= {}
type = type.underscore

if ::Rails.application.config.cache_classes
@_resource_type_to_class_cache ||= {}
@_resource_type_to_class_cache.fetch(type) do
@_resource_type_to_class_cache[type] = _resource_klass_for(type)
end
else
_resource_klass_for(type)
end
end

def _resource_klass_for(type)
type_with_module = type.start_with?(module_path) ? type : module_path + type
@_resource_type_to_class_cache.fetch(type) do
type_with_module = type.start_with?(module_path) ? type : module_path + type

resource_name = _resource_name_from_type(type_with_module)
resource_klass = resource_name.safe_constantize if resource_name
if resource_klass.nil?
fail NameError, "JSONAPI: Could not find resource '#{type}'. (Class #{resource_name} not found)"
resource_name = _resource_name_from_type(type_with_module)
resource_klass = resource_name.safe_constantize if resource_name
if resource_klass.nil?
fail NameError, "JSONAPI: Could not find resource '#{type}'. (Class #{resource_name} not found)"
end
@_resource_type_to_class_cache[type] = resource_klass
end
resource_klass
end

def resource_klass_for_model(model)
Expand Down

0 comments on commit 4cb43d9

Please sign in to comment.