Skip to content

Commit

Permalink
Merge pull request #3045 from jacobherrington/docs/using-active-recor…
Browse files Browse the repository at this point in the history
…d-in-decorators

Extend Decorator documentation
  • Loading branch information
jacobherrington committed Jan 29, 2019
2 parents 40810b0 + 7222dd2 commit ae29800
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions guides/source/developers/extensions/decorators.html.md
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

0 comments on commit ae29800

Please sign in to comment.