Skip to content

Commit

Permalink
Merge pull request #381 from avanrielly/av/add_parent_class_override
Browse files Browse the repository at this point in the history
Adding back in the parent class override for Noticed::ActiveJob
  • Loading branch information
excid3 committed Jan 23, 2024
2 parents 395db0a + 4b7de15 commit 901bf4a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ end
# @post.noticed_events.each { |ne| ne.notifications... }
```

#### ActiveJob Parent Class

Noticed uses its own `Noticed::ApplicationJob` as the base job for all notifications. In the event that you would like to customize the parent job class, there is a `parent_class` attribute that can be overridden with your own class. This should be done in a `noticed.rb` initializer.

```ruby
Noticed.parent_class = "ApplicationJob"
```

#### Handling Deleted Records

Generally we recommend using a `dependent: ___` relationship on your models to avoid cases where Noticed Events or Notifications are left lingering when your models are destroyed. In the case that they are or data becomes mis-matched, you’ll likely run into deserialization issues. That may be globally alleviated with the following snippet, but use with caution.
Expand All @@ -511,4 +519,3 @@ DATABASE_URL=postgres://127.0.0.1/noticed_test rails test

## 📝 License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

3 changes: 3 additions & 0 deletions lib/noticed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ module DeliveryMethods
autoload :Webhook, "noticed/delivery_methods/webhook"
end

mattr_accessor :parent_class
@@parent_class = "Noticed::ApplicationJob"

class ValidationError < StandardError
end

Expand Down
2 changes: 1 addition & 1 deletion lib/noticed/delivery_method.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Noticed
class DeliveryMethod < ApplicationJob
class DeliveryMethod < Noticed.parent_class.constantize
include ApiClient
include RequiredOptions

Expand Down

0 comments on commit 901bf4a

Please sign in to comment.