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

Extend Decorator documentation #3045

Merged
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
26 changes: 26 additions & 0 deletions guides/source/developers/extensions/decorators.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ total by $10 (or whatever your currency is).

[monkey-patch]: https://en.wikipedia.org/wiki/Monkey_patch

## Using class-level methods in decorators

In order to access some class-level methods, you'll need to define a special
method.

```ruby
module MyStore::ProductDecorator

# This is the place to define custom associations, delegations, scopes and
# other ActiveRecord stuff
def self.prepended(base)
base.has_many :comments, dependent: :destroy
base.scope :sellable, -> { base.where(...).order(...) }
base.delegate :something, to: :something
end

...

Spree::Product.prepend self
end
```

In this example, a decorator has been used to extend the functionality of
`Spree::Product`. The decorator includes an ActiveRecord association, scope,
and delegation.

## Decorators and Solidus upgrades

Decorators can complicate your Solidus upgrades. If you depend on decorators,
Expand Down