Skip to content
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

Avoid prepend accumulation problems #3474

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions core/lib/generators/solidus/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ def configure_application
application <<-RUBY
# Load application's model / class decorators
initializer 'spree.decorators' do |app|
# Ensure decorated constants are unloaded before reloading decorators
config.to_prepare_blocks.unshift -> { ActiveSupport::Dependencies.clear }

# Load application's decorators
config.to_prepare do
Dir.glob(Rails.root.join('app/**/*_decorator*.rb')) do |path|
require_dependency(path)
end
app.root.glob('app/**/*_decorator*.rb') { |path| require_dependency(path.to_s)
end
end

# Load application's view overrides
initializer 'spree.overrides' do |app|
config.to_prepare do
Dir.glob(Rails.root.join('app/overrides/*.rb')) do |path|
require_dependency(path)
end
app.root.glob('app/overrides/*.rb') { |path| require_dependency(path.to_s) }
end
end
RUBY
Expand Down
16 changes: 15 additions & 1 deletion guides/source/developers/customizations/decorators.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@ Solidus autoloads any file in the `/app` directory that has the suffix
`_decorator.rb`, just like any other Rails models or controllers. This allows
you to [monkey patch][monkey-patch] Solidus functionality for your store.

*Solidus install generator will add code such as this to `config/application.rb`*

```ruby
initializer 'spree.decorators' do |app|
# Ensure decorated constants are unloaded before reloading decorators
config.to_prepare_blocks.unshift -> { ActiveSupport::Dependencies.clear }

# Load application's decorators
config.to_prepare do
app.root.glob('app/**/*_decorator*.rb') { |path| require_dependency(path.to_s) }
end
end
```

For example, if you want to add a method to the `Spree::Order` model, you could
create `/app/models/mystore/order_decorator.rb` with the following contents:
create `/app/models/my_store/order_decorator.rb` with the following contents:

```ruby
module MyStore::OrderDecorator
Expand Down