Skip to content

Move decorators to Module.prepend for Zeitwerk compatibility#2

Open
spaghetticode wants to merge 3 commits intosolidus-3from
zeitwerk-compatibility
Open

Move decorators to Module.prepend for Zeitwerk compatibility#2
spaghetticode wants to merge 3 commits intosolidus-3from
zeitwerk-compatibility

Conversation

@spaghetticode
Copy link

Besides replacing class_eval with prepend, this change is adding the SpreePriceBooks namespace to these decorators to ensure their class name remains unique.

Besides replacing class_eval with prepend, this change is adding
the SpreePriceBooks namespace to these decorators to ensure their
class name remains unique.
@spaghetticode spaghetticode self-assigned this Oct 2, 2025
@spaghetticode spaghetticode requested a review from Copilot October 3, 2025 09:03
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors decorator files to use Module.prepend instead of class_eval for Zeitwerk compatibility. The changes organize decorators within the Spree::SpreePriceBooks namespace to ensure unique class names and prevent potential conflicts in autoloading systems.

Key changes include:

  • Converting all class_eval decorators to module-based decorators using prepend
  • Moving decorators to the Spree::SpreePriceBooks namespace
  • Relocating files to maintain proper namespacing structure

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
app/models/spree/store_decorator.rb Removed original store decorator using class_eval
app/models/spree/spree_price_books/variant_decorator.rb Converted to module-based decorator with prepend pattern
app/models/spree/spree_price_books/user_decorator.rb Converted to module-based decorator with prepend pattern
app/models/spree/spree_price_books/store_decorator.rb Added new namespaced store decorator using prepend
app/models/spree/spree_price_books/role_decorator.rb Added new namespaced role decorator using prepend
app/models/spree/spree_price_books/product_decorator.rb Converted to module-based decorator with prepend pattern
app/models/spree/spree_price_books/price_decorator.rb Added new namespaced price decorator using prepend
app/models/spree/role_decorator.rb Removed original role decorator using class_eval
app/models/spree/price_decorator.rb Removed original price decorator using class_eval
app/models/spree/order/spree_price_books/currency_updater_decorator.rb Added new namespaced currency updater decorator
app/models/spree/order/currency_updater_decorator.rb Removed original currency updater decorator using class_eval
app/helpers/spree/spree_price_books/base_helper_decorator.rb Added new namespaced base helper decorator
app/helpers/spree/base_helper_decorator.rb Removed original base helper decorator using class_eval
app/controllers/spree/admin/spree_price_books/products_controller_decorator.rb Added new namespaced products controller decorator
app/controllers/spree/admin/products_controller_decorator.rb Removed original products controller decorator using class_eval

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +4 to +6
-> { where currency: Spree::Config[:currency], price_book_id: Spree::PriceBook.default.id },
class_name: 'Spree::Price',
dependent: :destroy
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The association definition spans multiple lines but uses inconsistent indentation. Consider aligning the lambda block parameters consistently with the association declaration.

Suggested change
-> { where currency: Spree::Config[:currency], price_book_id: Spree::PriceBook.default.id },
class_name: 'Spree::Price',
dependent: :destroy
-> { where currency: Spree::Config[:currency], price_book_id: Spree::PriceBook.default.id },
class_name: 'Spree::Price',
dependent: :destroy

Copilot uses AI. Check for mistakes.
class_name: 'Spree::Price',
dependent: :destroy

base.has_many :prices,
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Similar to the previous association, the multi-line association definition should maintain consistent indentation for better readability.

Copilot uses AI. Check for mistakes.
@spaghetticode spaghetticode marked this pull request as ready for review October 3, 2025 09:08
- Fix initializer name from "spree_active_shipping.register.calculators"
  to "spree_price_books.register.calculators" (correct gem name)
- Add "after: spree.register.calculators" dependency to ensure proper
  initialization order
- Wrap calculator registration in after_initialize block to ensure Rails
  is fully initialized before registering calculators, which is required
  for Rails 7 and Zeitwerk autoloader compatibility
Fix calculator registration for Rails 7 and Zeitwerk compatibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants