noticed 1.2.10 → 1.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +54 -0
- data/lib/generators/noticed/model_generator.rb +1 -1
- data/lib/noticed/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f215fc7642db8db6a38ba3354c4d58ad1621c6d6af5c4ee479a519fdab1fae8d
|
4
|
+
data.tar.gz: 874dc986fa682f54eaee86f0e8e638049cb8d4f310a2e4d906e76ba11b5d7405
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '039b85fe5977ecf3d3353ba275f0913f03a325a3affc913a5edc05f07e5555b38deff9fd23b492d16fbdaa58c0c5e3cf281267288c3ff69697d07e0ff840ded8'
|
7
|
+
data.tar.gz: 7a49698a38596e35382fffc86d12857414f9f8ecdbc68f2c66fd24e124e6b893f62f442e736d004c5fad0403aa55eecc30a749843c6a61b5f0fc45d1b9da84c2
|
data/README.md
CHANGED
@@ -401,6 +401,60 @@ Check if read / unread:
|
|
401
401
|
@notification.unread?
|
402
402
|
```
|
403
403
|
|
404
|
+
#### Associating Notifications
|
405
|
+
|
406
|
+
Adding notification associations to your models makes querying and deleting notifications easy and is a pretty critical feature of most applications.
|
407
|
+
|
408
|
+
For example, in most cases, you'll want to delete notifications for records that are destroyed.
|
409
|
+
|
410
|
+
##### JSON Columns
|
411
|
+
|
412
|
+
If you're using MySQL or Postgresql, the `params` column on the notifications table is in `json` or `jsonb` format and can be queried against directly.
|
413
|
+
|
414
|
+
For example, we can query the notifications and delete them on destroy like so:
|
415
|
+
|
416
|
+
```ruby
|
417
|
+
class Post < ApplicationRecord
|
418
|
+
def notifications
|
419
|
+
# Exact match
|
420
|
+
@notifications ||= Notification.where(params: { post: self })
|
421
|
+
|
422
|
+
# Or Postgres syntax to query the post key in the JSON column
|
423
|
+
# @notifications ||= Notification.where("params->'post' = ?", Noticed::Coder.dump(self).to_json)
|
424
|
+
end
|
425
|
+
|
426
|
+
before_destroy :destroy_notifications
|
427
|
+
|
428
|
+
def destroy_notifications
|
429
|
+
notifications.destroy_all
|
430
|
+
end
|
431
|
+
end
|
432
|
+
```
|
433
|
+
|
434
|
+
##### Polymorphic Assocation
|
435
|
+
|
436
|
+
If your notification is only associated with one model or you're using a `text` column for your params column , then a polymorphic association is what you'll want to use.
|
437
|
+
|
438
|
+
1. Add a polymorphic association to the Notification model. `rails g migration AddNotifiableToNotifications notifiable:belongs_to{polymorphic}`
|
439
|
+
|
440
|
+
2. Add `has_many :notifications, as: :notifiable, dependent: :destroy` to each model
|
441
|
+
|
442
|
+
3. Customize database `format: ` option to write the `notifiable` attribute(s) when saving the notification
|
443
|
+
|
444
|
+
```ruby
|
445
|
+
class ExampleNotification < Noticed::Base
|
446
|
+
deliver_by :database, format: :format_for_database
|
447
|
+
|
448
|
+
def format_for_database
|
449
|
+
{
|
450
|
+
notifiable: params.delete(:post),
|
451
|
+
type: self.class.name,
|
452
|
+
params: params
|
453
|
+
}
|
454
|
+
end
|
455
|
+
end
|
456
|
+
```
|
457
|
+
|
404
458
|
## 🙏 Contributing
|
405
459
|
|
406
460
|
This project uses [Standard](https://github.com/testdouble/standard) for formatting Ruby code. Please make sure to run `standardrb` before submitting pull requests.
|
@@ -33,7 +33,7 @@ module Noticed
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def params_column
|
36
|
-
case ActiveRecord::Base.
|
36
|
+
case ActiveRecord::Base.configurations.configs_for(spec_name: "primary").config["adapter"]
|
37
37
|
when "mysql"
|
38
38
|
"params:json"
|
39
39
|
when "postgresql"
|
data/lib/noticed/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noticed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|