Comments (8)
The library is an optimization of the base case of adding code to a class, which is why we do it directly in the class without involving the module hierarchy.
So if you're involving the module hierarchy, then you'll have to involve modules all the way or not use an extension for that off case. So you'll need to either make the extension use a module or concern and include it (can be done in the extension), or move it out of the extensions directory.
That's the built-in way to control the loading. I'd like to have more documentation on Ruby's module system so it's easier for people to know what's going on here.
from conventional_extensions.
I think it makes sense for extensions that require a module mixin to include / extend that dependency themselves. There's no harm as far as I can tell from including the same module twice. If it's already included by the main class or another extension, it'll just be a no-op.
from conventional_extensions.
I think I understand you, but I am inly advocating for a way to disable load_extensions
being called automatically in AR models, so I can then control when I load extensions. For example:
class User < ApplicationRecord
include SomeConcerns
end
In the above case I need to load_extensions
after the inclusion of SomeConcerns
, and with non-AR classes, I can do that ...
class User < ApplicationRecord
include SomeConcerns
load_extensions
end
from conventional_extensions.
Yeah, I got all that, I'm just not interested in supporting it since it muddies the conceptual model (it's also technically impossible as far as I know to retain the automatic load_extensions
if we support this). The only thing I'd be ok with is a config flag to disable the auto load in Active Record and always have it be manual.
from conventional_extensions.
@joeldrapper also brought up the point that you could include the module within the extension too, and then the main class include
will be a no-op. I like that too.
from conventional_extensions.
I think the latter would be a great option then - disabling the auto-load completely. 👌
from conventional_extensions.
Yeah, on second thought I'm not interested in adding that based on what I've seen here. I want it to be always on for Active Records, and if you're doing anything more advanced for those off cases, you'll have to invoke the module hierarchy too — or not use an extension in that case. Thanks for the issue.
from conventional_extensions.
By the way, I ended up changing my mind and chopping the auto-load based on #10.
from conventional_extensions.
Related Issues (7)
- Test with Zeitwerk's reloading
- NoMethodError: `private method 'load' called for nil:NilClass` HOT 4
- ConventionalExtensions not automatically loading extensions for Active Record models HOT 2
- `dirname': no implicit conversion of false into String (TypeError) HOT 6
- Namespaced classes HOT 1
- Zeitwerk::NameError with Rails `eager_load` during tests HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from conventional_extensions.