forked from pay-rails/pay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add customizing pay models documentation pay-rails#59
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -396,6 +396,36 @@ user = User.find_by(email: '[email protected]') | |
user.subscription.processor_subscription | ||
``` | ||
|
||
### Customizing Pay Models | ||
|
||
Want to add methods to `Pay::Subscription` or `Pay::Charge`? You can | ||
define a concern and simply include it in the model when Rails loads the | ||
code. | ||
|
||
We'll be using the `to_prepare` method to allow our concerns to be | ||
included every time Rails reloads the models in development as well. | ||
|
||
```ruby | ||
# app/models/concerns/subscription_extensions.rb | ||
module SubscriptionExtensions | ||
extend ActiveSupport::Concern | ||
included do | ||
# associations and other class level things go here | ||
end | ||
# instance methods and code go here | ||
end | ||
```ruby | ||
# config/initializers/subscription_extensions.rb | ||
|
||
# Re-include the SubscriptionExtensions every time Rails reloads | ||
Rails.application.config.to_prepare do | ||
Pay.subscription_model.include SubscriptionExtensions | ||
end | ||
``` | ||
|
||
## Contributors | ||
|
||
- [Jason Charnes](https://twitter.com/jmcharnes) | ||
|