This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.
Message originally sent by slack user U71TN2WF04X
Hello I’ve got a question.
Is there a way to list a dependency to a specific file inside a pack? I’ve been giving workshops to my coworkers about packwerk and packs-rails, and this question is been repeated a few times.
The question comes when in a specific pack I list another as a dependency to use whatever is defined in there, but what if I only need a very specific model as a dependency and not the whole pack? I imagine a way of doing this would be to create a pack inside like packs/another_pack/app/models/my_model/ → becomes a pack and inside I put my_model.rb, but would it make sense to make this happen? Maybe someone here has tried a different approach
You can also use the packwerk extension PrivacyChecker to create the concept of package code privacy, which allows you to say that in a given package you want certain packages to form the public API, but hide every other class. If a package now accepts the dependency and depends only on the file in the public API, you won’t see any violations. If, however, that package also depends on non-public code, you will get a new kind of violation: a privacy violation
It should be noted that a very similar but slightly more convoluted thing can be achieved without the privacy checker - the public API of a package can be a separate package. Like „inventory“ and „inventory_private“. By convention, nobody would depend on the private thing (except „inventory“ itself).
Privacy-checker will be a lot more intuitive once it is set up - just saying, once again, all packaging problems can be solved by introducing more packages