Skip to content

Commit f3c6d83

Browse files
speckinsiNecas
authored andcommitted
Load file directly instead of using Rails constant loading to do so
- Since Rails constant loading looks in Rails eager_load and autoload paths, it's possible for files outside of api_controllers_matcher to be loaded. - Files that do not define an expected constant will cause a NameError to be raised. This was most commonly encountered with files in the concerns/ directory, which caused a NameError for a missing "Concerns::<name>" constant. This makes use of ActiveSupport::Dependencies::Loadable#require_dependency to explicitly load the file and its constants in a way that cooperates with Rails constant loading and unloading. https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#require-dependency https://api.rubyonrails.org/classes/ActiveSupport/Dependencies/Loadable.html#method-i-require_dependency Fixes Apipie#347.
1 parent f2540a6 commit f3c6d83

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

lib/apipie/application.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,7 @@ def get_resource_version(resource_description)
434434
end
435435

436436
def load_controller_from_file(controller_file)
437-
controller_class_name = controller_file.gsub(/\A.*\/app\/controllers\//,"").gsub(/\.\w*\Z/,"").camelize
438-
controller_class_name.constantize
437+
require_dependency controller_file
439438
end
440439

441440
def ignored?(controller, method = nil)

0 commit comments

Comments
 (0)