diff --git a/lib/jsonapi/resource_common.rb b/lib/jsonapi/resource_common.rb index ea17d14b..9ec4e0d1 100644 --- a/lib/jsonapi/resource_common.rb +++ b/lib/jsonapi/resource_common.rb @@ -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)