Code Monkey home page Code Monkey logo

Comments (8)

kaspth avatar kaspth commented on September 22, 2024

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.

joeldrapper avatar joeldrapper commented on September 22, 2024

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.

joelmoss avatar joelmoss commented on September 22, 2024

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.

kaspth avatar kaspth commented on September 22, 2024

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.

kaspth avatar kaspth commented on September 22, 2024

@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.

joelmoss avatar joelmoss commented on September 22, 2024

I think the latter would be a great option then - disabling the auto-load completely. 👌

from conventional_extensions.

kaspth avatar kaspth commented on September 22, 2024

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.

kaspth avatar kaspth commented on September 22, 2024

By the way, I ended up changing my mind and chopping the auto-load based on #10.

from conventional_extensions.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.