Skip to content
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

Use autoloading instead of requiring all files up front #1317

Closed
mcmire opened this issue Jul 11, 2020 · 9 comments
Closed

Use autoloading instead of requiring all files up front #1317

mcmire opened this issue Jul 11, 2020 · 9 comments

Comments

@mcmire
Copy link
Collaborator

mcmire commented Jul 11, 2020

We have a lot of files which are like active_record.rb where there are a bunch of requires at the top of the file. I've never liked this because there are different files at different levels being required. This is not as organized as it could be, and if you add a new file, it's confusing where to add the require. I've started using autoload in other projects and I find it easier to manage. We should do the same thing here.

For instance, for active_record.rb, we might change this to something like:

module Shoulda
  module Matchers
    module ActiveRecord
      autoload :AssociationMatcher, "shoulda/matchers/active_record/association_matcher"
      autoload :AssociationMatchers, "shoulda/matchers/active_record/association_matchers"
      autoload :HaveDbColumnMatcher, "shoulda/matchers/active_record/have_db_column_matcher"
      # ...
    end
  end
end
@vsppedro
Copy link
Collaborator

Hi, @mcmire, I would love to work on this!

@mcmire
Copy link
Collaborator Author

mcmire commented Jul 11, 2020

@vsppedro Okay, that would be awesome! I will assign this to you :)

@vsppedro
Copy link
Collaborator

Thanks!

@n-rodriguez
Copy link

@mcmire why not using Zeitwerk?

@mcmire
Copy link
Collaborator Author

mcmire commented Aug 26, 2020

@n-rodriguez I'm not sure that Zeitwerk would be a good choice here. It seems like it's really well suited for applications, but it seems overkill for gems IMO. It would have to be added as a runtime dependency and I don't feel like people should have to bring in Zeitwerk to use shoulda-matchers.

@n-rodriguez
Copy link

but it seems overkill for gems IMO.

IMO this PR is the perfect use case for Zeitwerk since you do exactly what it does.

@vsppedro
Copy link
Collaborator

@mcmire First, sorry for the problems with the PR and thank you for releasing the fix so fast.

For now, I will focus on adding the tests first, as described by you here: #1333 (comment). After adding these tests I will continue with this PR - if that's okay with you.

@mcmire
Copy link
Collaborator Author

mcmire commented Aug 27, 2020

@vsppedro Yeah, that's fine with me!

@mcmire
Copy link
Collaborator Author

mcmire commented Mar 23, 2021

I'm going to close this issue. It seems like this is a relatively minor pain point and is actually more complicated than I thought it would be.

@mcmire mcmire closed this as completed Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants