Skip to content

Load file directly instead of using Rails constant loading to do so #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2019

Conversation

speckins
Copy link

  • Since Rails constant loading looks in Rails load 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::" constant.

This make 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 #347.

@iNecas
Copy link
Member

iNecas commented May 22, 2019

Thanks @speckins for looking into this: mind rebasing: I've just updated the travis matrix and some unrelated fixes that caused the tests to fail

@speckins speckins force-pushed the load-files-instead-of-constants branch from c3b2f0c to 56517cc Compare May 22, 2019 13:25
- 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.
@speckins
Copy link
Author

@iNecas Rebased.

Copy link
Member

@iNecas iNecas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks like everything works fine (tested code reloading on separate app, as well as static generation)

@iNecas iNecas merged commit f3c6d83 into Apipie:master May 22, 2019
@iNecas
Copy link
Member

iNecas commented May 22, 2019

apipie-0.5.16 released to rubygems. Thanks @speckins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Controller concerns
2 participants