What's the current decorator convention?
# general
b
What's the current decorator convention?
j
app/overrides/my_store/spree/product_decorator.rb
Copy code
module MyStore::Spree::ProductDecorator
  # ...

  Spree::Product.prepend self
end
I've started using ActiveSupport::Concern for all my decorators for convenience. Makes handling class methods and stuff a bit nicer.
b
Not sure how I feel about namespacing the namespace.
j
if you call it
Spree::ProductDecorator
and any extension does that too, you'll collide
b
The original point for namespacing in a Rails app with Spree (at the time) was to help convey to developers "Hey, this is actually your Rails app, Spree is still a guest and an engine."
Ah, I see.
j
plus it makes it clear if you look at the ancestors when you're debugging what the source of the decorators is
šŸ‘Œ 1
šŸ‘ŒšŸ¼ 1
w
In fact, there's no decorator convention anymore. Please, see https://github.com/solidusio/solidus/pull/4231. But if you need to monkey patch, yeah, using
prepend
is the less obtrusive one. However, before doing that, always consider if you can: • Use a custom service class • Use an event handler See https://edgeguides.solidus.io/customization/customizing-the-core for details