-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1976 from ruby-grape/bugfix/autoload
Be sure classes/modules listed for autoload really exist
- Loading branch information
Showing
4 changed files
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
# Grape uses autoload https://api.rubyonrails.org/classes/ActiveSupport/Autoload.html. | ||
# When a class/module get added to the list, ActiveSupport doesn't check whether it really exists. | ||
# This method loads all classes/modules defined via autoload to be sure only existing | ||
# classes/modules were listed. | ||
def eager_load!(scope = Grape) | ||
# get modules | ||
scope.constants.each do |const_name| | ||
const = scope.const_get(const_name) | ||
|
||
next unless const.respond_to?(:eager_load!) | ||
|
||
const.eager_load! | ||
|
||
# check its modules, they might need to be loaded as well. | ||
eager_load!(const) | ||
end | ||
end |