-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
RFC: Change *_decorator pattern #3010
Comments
We can deprecate the That's assuming that the 3.0 release (https://github.com/solidusio/solidus/milestone/16) isn't too far off. |
This is relevant doc from Rails: https://guides.rubyonrails.org/engines.html#a-note-on-decorators-and-loading-code Not sure if this habit came first on Rails or on Spree, but it might be good to adhere to whatever standard Rails has (except for extremely good reasons). |
@elia didn't know that, great find! I think that could be a good reason to keep it as is then. |
If we keep it the way it is, let's document why we do that here: https://github.com/solidusio/solidus/blob/master/guides/source/developers/extensions/decorators.html.md |
@kennyadsl the merit goes to @bitberryru, also noting that those aren't actual decorators. I agree that article should be linked in the docs. Maybe would be good to fix Rails docs too, if we come up with a good proposal. |
Of course, I support it :) The name should be changed, it will not break anything but this will be consistent with the principle of least surprise/astonishment. It is ruby way for sure.
It would be great 👍🏻👍🏻👍🏻 |
What about this part of Rails docs:
Working on Solidus I found having to use Could it worth the effort? |
Not sure to understand. We could move core things into concerns but still need some mechanism to change Solidus core functionalities into applications, which is where "decorators" are used. Could you please explain this more in depth @mdesantis ? |
@kennyadsl well, actually I didn't try anything practical, I'm checking what they mean in the Rails docs just now. Basically, if in Solidus you move all the class logic to a main concern, e.g.: module Spree
class PromotionRule < Spree::Base
include Spree::Models::PromotionRule
def hello
'Hello from Solidus'
end
end
end Then in your application you could have: module Spree
class PromotionRule < Spree::Base
include Spree::Models::PromotionRule
def hello
"#{super} and from my app"
end
end
end But it's actually not a "decoration", it's a "redefinition + include all the previous logic": you are actually redefining module Spree
class PromotionRule < Spree::Base
include Spree::Models::PromotionRule
include Spree::SomeExtension::Models::PromotionRule
def hello
"#{super} and from my app"
end
end
end Moreover, you'll have to do the same for every class defined by Solidus (e.g. in the example above if you want to customize I'm unsure whether is better or not: from one hand it makes your app classes more explicit about what they include, from the other hand it's more verbose than |
@mdesantis As far as I understand, you are trying to re-invent "prepend" :) For my application, I use my own
And typical override looks like
As you see you can use This allows you to extend any external classes and use inheritance features like you're declaring a child class. |
@bitberryru you're right, I was re-inventing
Anyway, great news on the Rails side: rails/rails#34946 has been merged, so now it's official that talking about decorators in this context it's not appropriate! |
As of today, rails docs still read
:( |
Not sure why, but it's updated on master. 🤔 |
I am 💯 for making this change as this always bugged me for above mentioned reasons 👏 But, I wholeheartedly disagree with calling them Also, Deface, a still widely used gem in Solidus ecosystem, already uses the |
Hi guys, Finally, a beautiful autoloader in Rails now. Unfortunately, documentation lacks information on how to load decorators by using it. You might have come across some tips, such as using require, load, or require_dependency, though all of them are wrong or even harmful. I’ve researched zeitwerk API and have found an excellent method called preload, which is suitable for decorators. By using it, you can select files which need to be loaded first and it will follow this during an initial setup and reloading. This is exactly what we need for decorators loading, because decorators are the part of the code that should be loaded first like gems. Below you can find an example of my production code. You just add once your decorators in a preload list and everything will be working perfectly well. If changes are made, code will reboot correctly, zeitwerk will do all the job.
There are couple of moments. The current approach for loading decorators in solidus engines (https://github.com/solidusio/solidus_support/blob/master/lib/solidus_support/engine_extensions.rb#L36) calls require_dependency in I suggest starting to use preload in engines, for example, declaring them in initializers before zeitwerk “takes over”.
Such an approach will allow inject decorator into any part of the ancestors chain on application-level. Let’s say there are 2 different decorators from 2 different gems and we want to inject exactly between them. We can do it. This gives us so much flexibility, that we couldn’t even dream of before! As an option, you can continue to load engine decorators as you did in the past (require, load, require_dependency), but then I would ask you to do it only once at any convenient time for you. Mostly importantly that after it I would be able to call zeitwerk’s preload. Decorators need clearer practices and better name. What do you think about this? Let's talk. |
@bitberryru thanks a lot for your insights, let's talk! 🙂 The call at https://github.com/solidusio/solidus_support/blob/master/lib/solidus_support/engine_extensions.rb#L36 is needed because those files are never referenced in the codebase (like any other class/module) and unless we don't require them "manually" on every app reload (with Please also consider that the approach taken is needed to support both Rails with and without Zeitwerk autoloader so I guess we can't use the preload feature, isn't it? What about changing how you load decorators in your application in order to have them loaded with the "barbarously" (😆) way which I think would preserve the loading order as the first boot? |
@bitberryru I quickly checked the implementation of My initial though when I saw zeitwerk was that we could write a mapper that tries to load any @kennyadsl if a better way to support reloading of decorators comes available through zeitwerk I think a config switch would make a lot of sense and solve many problems for those who choose that path. Would that be acceptable? Anyway I too think we should solve the |
Yes, of course I understand that :) I asked this because at the application level you do not need to reload the gem's decorators because their code does not change.
Well, in general we can support both. But also keep in mind that classic mode is discouraged for new applications. I don’t think it's worth focusing on classic autoloader.
Yes, for some time it will still work while zeitwerk allows it. But for zeitwerk it is barbarous way :)) because it is assumed that the application code should be loaded with an autolader.
Yep, it will and it will always preserve load order.
I began to think that only I had various problems with the classic autoloader and the "classic" approach to loading decorators. But I'm not alone 👍 |
I think what we are doing is also what Zeitwerk expects in this scenario. Please, take a look at solidusio/solidus_support#43. Anyway, I totally understand that we need to solve this issue. This could be via code or via some good documentation around how to create decorators and where to place them in order to be compliant with the new Rails autoloader. Would you be available for a chat in Slack in the next days? |
Yep, it expects and all works because Zeitwerk overrides Kernel's In short, I think a more idiomatic and preferred way to load code is to use autoloader api.
Yes, I’ll come now |
Last week me and @spaghetticode finally got around to leveraging Zeitwerk to do things in the right way™ and this PR is the resulting work: |
At this point, Rails encourage in its guides a way to monkey patch from the application: https://guides.rubyonrails.org/engines.html#overriding-models-and-controllers
As we see, it uses the word Another issue is how you monkey patch those classes. In Ruby and Rails, you have several options. To name a few:
The Rails guides talk about two of them: Existing an official way to implement that pattern, I'd say we don't need to do anything besides linking to the Rails guides. Even more, taking into account that our goal should be to provide actual extensibility through the injection of services or a similar pattern. However, we have to add deface into the equation. The problem with We did some tests in this repository https://github.com/waiting-for-dev/rails_overrides with a bare rails app:
The repository has several branches which test different combinations of There's also a The "help" given by |
I agree that we should adopt the Rails convention for overriding engines instead of trying to reinvent the wheel. Perhaps we can have a preferred way of doing the overrides (concerns?), because extensive use of class_eval leads to a lot of problems and should be discouraged, while the Rails guides take a neutral approach towards it. As for Deface, I don't think getting rid of it will be as simple as removing it from solidus_auth_devise unfortunately (although we should definitely do that). While we strongly discourage extensions from attempting to override anything in the frontend, Deface is still the only (more or less) maintainable way to override things in the backend, and a lot of extensions use it precisely for that purpose. The only alternative is replacing entire backend views, which obviously doesn't work when you install multiple extensions that all override the same view, and makes upgrading Solidus a nightmare. We've talked a lot about how to get rid of Deface for the backend, and the final solution will most likely require providing more extension hooks for the backend UI (similar to what we already do for menu items) and introducing ViewComponent (so that it's easier to override or configure tiny pieces of the backend in isolation). For the time being, I think that we should allow Deface to accept the overrides path as a configuration option, and push to deprecate and then remove the default setting of |
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see solidusio#3010 (comment)). We decided to tackle the issue upstream on `deface` (see solidusio#3010 (comment)). Closes solidusio#3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see #3010 (comment)). We decided to tackle the issue upstream on `deface` (see #3010 (comment)). Closes #3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see #3010 (comment)). We decided to tackle the issue upstream on `deface` (see #3010 (comment)). Closes #3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see #3010 (comment)). We decided to tackle the issue upstream on `deface` (see #3010 (comment)). Closes #3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see #3010 (comment)). We decided to tackle the issue upstream on `deface` (see #3010 (comment)). Closes #3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see #3010 (comment)). We decided to tackle the issue upstream on `deface` (see #3010 (comment)). Closes #3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see #3010 (comment)). We decided to tackle the issue upstream on `deface` (see #3010 (comment)). Closes #3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see #3010 (comment)). We decided to tackle the issue upstream on `deface` (see #3010 (comment)). Closes #3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see #3010 (comment)). We decided to tackle the issue upstream on `deface` (see #3010 (comment)). Closes #3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see #3010 (comment)). We decided to tackle the issue upstream on `deface` (see #3010 (comment)). Closes #3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see #3010 (comment)). We decided to tackle the issue upstream on `deface` (see #3010 (comment)). Closes #3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see solidusio#3010 (comment)). We decided to tackle the issue upstream on `deface` (see solidusio#3010 (comment)). Closes solidusio#3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see solidusio#3010 (comment)). We decided to tackle the issue upstream on `deface` (see solidusio#3010 (comment)). Closes solidusio#3010
Up to this PR, when installing Solidus, we're adding code to the host application to load files matching `app/**/*_decorator*.rb`. There exist a series of issues about that: - It goes against current recommendations on the Rails guides, where overrides are placed under `app/overrides/**/_*override.rb` ( see https://guides.rubyonrails.org/engines.html#improving-engine-functionality). - The `_decorator.rb` suffix is misleading, as that kind of overrides has to be seen as monkey patches and not related to the decorator pattern (see https://en.wikipedia.org/wiki/Decorator_pattern). - Although it's something needed a lot of times, monkey patching core classes should be seen as a last resort after ruling out other strategies (like configuring a custom class for some behavior). As such, we should not encourage it. - It may conflict with the naming used by other gems, like Draper (https://github.com/drapergem/draper). For all of that, it's something that we should address in the docs. This change is backward compatible, as the running code doesn't belong to the Solidus engine but to the previously generated applications, which will keep it after upgrading. The deleted code is, in fact, intended to work with the classic autoloader (removed on Rails 7). However, it still works because of https://github.com/rails/rails/blob/296ef7a17221e81881e38b51aa2b014d7a28bac5/activesupport/lib/active_support/dependencies/require_dependency.rb, which is deprecated. We add a notice to the CHANGELOG to let users known about that. On a related information, the recommended `app/overrides/` directory is the same used by `deface` (https://github.com/spree/deface), a common dependency in Solidus projects. However, both types of overrides can coexist without interfering with each other (see solidusio#3010 (comment)). We decided to tackle the issue upstream on `deface` (see solidusio#3010 (comment)). Closes solidusio#3010
The Solidus suggested way to extend Ruby classes coming from core and extensions into users' applications is by creating files that end with
_decorator.rb
into the/app
folder of the main application.Despite this is not mandatory and users can change this pattern, this is suggested by us with the install generator that pushes this code into
config/application.rb
I think this is not a good pattern and we should stop using/promoting it:
I hope this issue helps to answer these questions:
The text was updated successfully, but these errors were encountered: