notification-handler 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +43 -185
- data/lib/notifications-rails.rb +6 -0
- metadata +5 -17
- data/app/models/notification_handler/notification.rb +0 -8
- data/lib/generators/notification_handler/install_generator.rb +0 -46
- data/lib/generators/templates/install/initializer.rb +0 -12
- data/lib/generators/templates/install/notification_model.rb +0 -4
- data/lib/generators/templates/install/notifications_migration.rb.erb +0 -16
- data/lib/notification-handler.rb +0 -14
- data/lib/notification_handler/configuration.rb +0 -31
- data/lib/notification_handler/engine.rb +0 -15
- data/lib/notification_handler/group.rb +0 -22
- data/lib/notification_handler/notification_lib.rb +0 -64
- data/lib/notification_handler/notification_scopes.rb +0 -21
- data/lib/notification_handler/object.rb +0 -22
- data/lib/notification_handler/target.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44da09c04b6282f1d6eba56e5a195858d5646964e5e7f6e1ee47eda4252d7df2
|
4
|
+
data.tar.gz: acbc2f716492d9450c40d294c91b3a6145e9520bc4a3c942211d9e3f7df668b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41d91481c7d251290aa7c3a12cec7cfa778f74aeb579a3ea7224a3e3947c9736aa0fe8d339d3ec5af16492391c41828d50384b37ab976eff004d842ffe78e5ea
|
7
|
+
data.tar.gz: f658cb7133391ac215459a7831b50a6280a4d4aa2e9c2f3d8541725749154197663eec3d83050b27f80a3805fc7bd7c3a8cbcefeed33ce3fee8ba680ece76f3e
|
data/README.md
CHANGED
@@ -1,226 +1,84 @@
|
|
1
|
-
#
|
1
|
+
# notifications-rails
|
2
2
|
|
3
|
-
|
3
|
+
notifications-rails is the most powerful notification library for Rails. It offers not only simple APIs to create and render notifications but also supports user-integration and cross-platform delivery of notifications.
|
4
4
|
|
5
|
-
|
5
|
+
## Philosophy
|
6
6
|
|
7
|
-
|
7
|
+
notifications-rails has been built with modularity in mind. It currently consists of four components each of which bringing one essential functionality to the integration of notifications in your Rails app.
|
8
8
|
|
9
|
-
|
9
|
+
**[notification-handler](notification-handler):** Create and modify your notifications through a simple API.
|
10
10
|
|
11
|
-
|
12
|
-
* [Usage](#usage)
|
13
|
-
* [`Notification` API](#notification-api)
|
14
|
-
* [`notification_target`](#notification_target)
|
15
|
-
* [`notification_object`](#notification_object)
|
16
|
-
* [Groups](#groups)
|
17
|
-
* [Defining a group](#defining-a-group)
|
18
|
-
* [Using a group](#using-a-group)
|
19
|
-
* [Caching](#caching)
|
20
|
-
* [Configuration](#configuration)
|
21
|
-
* [To Do](#to-do)
|
22
|
-
* [Contributing](#contributing)
|
23
|
-
* [Semantic versioning](#semantic-versioning)
|
11
|
+
**[notification-renderer](notification-renderer):** Render your notifications in various contexts.
|
24
12
|
|
25
|
-
|
13
|
+
**[notification-pusher](notification-pusher):** Deliver your notifications to various services, including [Email](notification-pusher/notification-pusher-actionmailer) and [OneSignal](notification-pusher/notification-pusher-onesignal).
|
26
14
|
|
27
|
-
|
28
|
-
|
29
|
-
NotificationHandler works with Rails 5 onwards. You can add it to your `Gemfile` with:
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
gem 'notification-handler'
|
33
|
-
```
|
34
|
-
|
35
|
-
And then execute:
|
36
|
-
|
37
|
-
$ bundle
|
38
|
-
|
39
|
-
Or install it yourself as:
|
40
|
-
|
41
|
-
$ gem install notification-handler
|
42
|
-
|
43
|
-
Now run the generator:
|
44
|
-
|
45
|
-
$ rails g notification_handler:install
|
46
|
-
|
47
|
-
To wrap things up, migrate the changes to your database:
|
48
|
-
|
49
|
-
$ rails db:migrate
|
50
|
-
|
51
|
-
---
|
52
|
-
|
53
|
-
## Usage
|
54
|
-
|
55
|
-
### `Notification` API
|
56
|
-
|
57
|
-
You can use all the ActiveRecord methods you know and love on your `Notification` class. So creating a new notification is dead simple:
|
58
|
-
|
59
|
-
```ruby
|
60
|
-
notification = Notification.new
|
61
|
-
```
|
62
|
-
|
63
|
-
Every `Notification` object has a `target` record. This target record is the object, that this notification belongs to (or targets). Usually it's a user, but it can be a record of any class:
|
64
|
-
|
65
|
-
```ruby
|
66
|
-
notification.target = User.first
|
67
|
-
```
|
68
|
-
|
69
|
-
To store information in your `Notification` record you can use the `metadata` attribute that gets serialized as a `Hash`:
|
70
|
-
|
71
|
-
```ruby
|
72
|
-
notification.metadata = {
|
73
|
-
title: 'My first notification',
|
74
|
-
content: "It looks great, doesn't it?"
|
75
|
-
}
|
76
|
-
```
|
15
|
+
**[notification-settings](notification-settings):** Integrates with your authentication solution to craft a personalized user notification platform.
|
77
16
|
|
78
|
-
|
79
|
-
|
80
|
-
```ruby
|
81
|
-
notification.object = Recipe.first
|
82
|
-
```
|
83
|
-
|
84
|
-
The `read` attribute determines whether a notification has been seen or not:
|
85
|
-
|
86
|
-
```ruby
|
87
|
-
notification.read = true
|
88
|
-
notification.read? # true
|
89
|
-
notification.unread? # false
|
90
|
-
```
|
91
|
-
|
92
|
-
You can use scopes to filter for read or unread notifications:
|
93
|
-
|
94
|
-
```ruby
|
95
|
-
# Return all read notifications
|
96
|
-
Notification.read
|
17
|
+
You may just use the components you actually need, or instead use this gem to bundle everything for a complete notification solution.
|
97
18
|
|
98
|
-
|
99
|
-
Notification.unread
|
100
|
-
|
101
|
-
# Number of unread notifications
|
102
|
-
Notification.unread.size
|
103
|
-
```
|
104
|
-
|
105
|
-
### `notification_target`
|
106
|
-
|
107
|
-
To use records of an ActiveRecord class as notification targets, add the following to your class:
|
108
|
-
|
109
|
-
```ruby
|
110
|
-
class User < ApplicationRecord
|
111
|
-
notification_target
|
112
|
-
end
|
113
|
-
```
|
114
|
-
|
115
|
-
Now belonging notifications are easy to access:
|
116
|
-
|
117
|
-
```ruby
|
118
|
-
notifications = User.first.notifications
|
119
|
-
```
|
120
|
-
|
121
|
-
You can create a notification from a `target`:
|
122
|
-
|
123
|
-
```ruby
|
124
|
-
User.first.notify(object: Recipe.first)
|
125
|
-
```
|
126
|
-
|
127
|
-
### `notification_object`
|
128
|
-
|
129
|
-
When using records of an ActiveRecord class as notification objects, add this to your class:
|
130
|
-
|
131
|
-
```ruby
|
132
|
-
class Recipe < ApplicationRecord
|
133
|
-
notification_object
|
134
|
-
end
|
135
|
-
```
|
136
|
-
|
137
|
-
Now associated notifications are easy to access:
|
138
|
-
|
139
|
-
```ruby
|
140
|
-
notifications = Recipe.first.belonging_notifications
|
141
|
-
```
|
142
|
-
|
143
|
-
### Groups
|
144
|
-
|
145
|
-
Groups are a powerful way to bulk-create notifications for multiple objects that don't necessarily have a common class.
|
146
|
-
|
147
|
-
#### Defining a group
|
19
|
+
## Installation
|
148
20
|
|
149
|
-
You
|
21
|
+
You can add notifications-rails to your `Gemfile` with:
|
150
22
|
|
151
23
|
```ruby
|
152
|
-
|
153
|
-
config.define_group :subscribers, -> { User.where(subscriber: true) }
|
154
|
-
end
|
24
|
+
gem 'notifications-rails'
|
155
25
|
```
|
156
26
|
|
157
|
-
|
27
|
+
And then run:
|
158
28
|
|
159
|
-
|
160
|
-
NotificationHandler.configure do |config|
|
161
|
-
config.define_group :subscribers, -> { User.where(subscriber: true) + Admin.all }
|
162
|
-
config.define_group :company_members, lambda { |company_id|
|
163
|
-
User.with_role(:member, Company.find(company_id)
|
164
|
-
}
|
165
|
-
end
|
166
|
-
```
|
29
|
+
$ bundle install
|
167
30
|
|
168
|
-
|
31
|
+
Or install it yourself as:
|
169
32
|
|
170
|
-
|
33
|
+
$ gem install notifications-rails
|
171
34
|
|
172
|
-
|
35
|
+
If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
|
173
36
|
|
174
37
|
```ruby
|
175
|
-
notifications
|
176
|
-
notifications = Notification.for_group(:company_members, args: [4], attrs: { object: Recipe.first })
|
38
|
+
gem 'notifications-rails', github: 'jonhue/notifications-rails'
|
177
39
|
```
|
178
40
|
|
179
|
-
|
41
|
+
## Usage
|
180
42
|
|
181
|
-
|
43
|
+
Details on usage are provided in the [documentation](#philosophy) of the specific modules.
|
182
44
|
|
183
|
-
|
45
|
+
## Development
|
184
46
|
|
185
|
-
|
47
|
+
To start development you first have to fork this repository and locally clone your fork.
|
186
48
|
|
187
|
-
|
49
|
+
Install the projects dependencies by running:
|
188
50
|
|
189
|
-
|
190
|
-
add_column :user, :read_notification_count, :integer
|
191
|
-
add_column :user, :unread_notification_count, :integer
|
192
|
-
```
|
51
|
+
$ bundle install
|
193
52
|
|
194
|
-
|
53
|
+
### Testing
|
195
54
|
|
196
|
-
|
55
|
+
Tests are written with RSpec. Integration tests are located in `/spec`, unit tests can be found in `<module>/spec`.
|
197
56
|
|
198
|
-
|
57
|
+
To run all tests:
|
199
58
|
|
200
|
-
|
201
|
-
NotificationHandler.configure do |config|
|
202
|
-
config.cache = true
|
203
|
-
end
|
204
|
-
```
|
205
|
-
|
206
|
-
**`cache`** Cache amount of unread and read notifications for notification targets. Takes a boolean. Defaults to `false`.
|
59
|
+
$ ./rspec
|
207
60
|
|
208
|
-
|
61
|
+
To run RuboCop:
|
209
62
|
|
210
|
-
|
63
|
+
$ bundle exec rubocop
|
211
64
|
|
212
|
-
|
65
|
+
You can find all commands run by the CI workflow in `.github/workflows/ci.yml`.
|
213
66
|
|
214
|
-
|
67
|
+
## Contributing
|
215
68
|
|
216
|
-
|
69
|
+
We warmly welcome everyone who is intersted in contributing. Please reference our [contributing guidelines](CONTRIBUTING.md) and our [Code of Conduct](CODE_OF_CONDUCT.md).
|
217
70
|
|
218
|
-
##
|
71
|
+
## Releases
|
219
72
|
|
220
|
-
|
73
|
+
[Here](https://github.com/jonhue/notifications-rails/releases) you can find details on all past releases. Unreleased breaking changes that are on the current master can be found [here](CHANGELOG.md).
|
221
74
|
|
222
|
-
|
75
|
+
notifications-rails follows Semantic Versioning 2.0 as defined at http://semver.org. Reference our [security policy](SECURITY.md).
|
223
76
|
|
224
|
-
###
|
77
|
+
### Publishing
|
225
78
|
|
226
|
-
|
79
|
+
1. Review breaking changes and deprecations in `CHANGELOG.md`.
|
80
|
+
1. Change the gem version in `VERSION`.
|
81
|
+
1. Reset `CHANGELOG.md`.
|
82
|
+
1. Create a pull request to merge the changes into `master`.
|
83
|
+
1. After the pull request was merged, create a new release listing the breaking changes and commits on `master` since the last release.
|
84
|
+
1. The release workflow will publish the gems to RubyGems.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notification-handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Hübotter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -151,26 +151,14 @@ dependencies:
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
description: Create and modify your notifications through a simple API.
|
154
|
-
email:
|
154
|
+
email: jonas.huebotter@gmail.com
|
155
155
|
executables: []
|
156
156
|
extensions: []
|
157
157
|
extra_rdoc_files: []
|
158
158
|
files:
|
159
159
|
- LICENSE
|
160
160
|
- README.md
|
161
|
-
-
|
162
|
-
- lib/generators/notification_handler/install_generator.rb
|
163
|
-
- lib/generators/templates/install/initializer.rb
|
164
|
-
- lib/generators/templates/install/notification_model.rb
|
165
|
-
- lib/generators/templates/install/notifications_migration.rb.erb
|
166
|
-
- lib/notification-handler.rb
|
167
|
-
- lib/notification_handler/configuration.rb
|
168
|
-
- lib/notification_handler/engine.rb
|
169
|
-
- lib/notification_handler/group.rb
|
170
|
-
- lib/notification_handler/notification_lib.rb
|
171
|
-
- lib/notification_handler/notification_scopes.rb
|
172
|
-
- lib/notification_handler/object.rb
|
173
|
-
- lib/notification_handler/target.rb
|
161
|
+
- lib/notifications-rails.rb
|
174
162
|
homepage: https://github.com/jonhue/notifications-rails/tree/master/notification-handler
|
175
163
|
licenses:
|
176
164
|
- MIT
|
@@ -191,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
179
|
- !ruby/object:Gem::Version
|
192
180
|
version: '0'
|
193
181
|
requirements: []
|
194
|
-
rubygems_version: 3.
|
182
|
+
rubygems_version: 3.1.4
|
195
183
|
signing_key:
|
196
184
|
specification_version: 4
|
197
185
|
summary: Create and modify your notifications through a simple API
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators'
|
4
|
-
require 'rails/generators/migration'
|
5
|
-
|
6
|
-
module NotificationHandler
|
7
|
-
class InstallGenerator < Rails::Generators::Base
|
8
|
-
include Rails::Generators::Migration
|
9
|
-
|
10
|
-
source_root(File.join(File.dirname(__FILE__), '../templates/install'))
|
11
|
-
desc 'Install NotificationHandler'
|
12
|
-
|
13
|
-
def self.next_migration_number(dirname)
|
14
|
-
if ActiveRecord::Base.timestamped_migrations
|
15
|
-
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
16
|
-
else
|
17
|
-
format('%<migration_number>.3d',
|
18
|
-
migration_number: current_migration_number(dirname) + 1)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def create_initializer
|
23
|
-
template 'initializer.rb', 'config/initializers/notification_handler.rb'
|
24
|
-
end
|
25
|
-
|
26
|
-
def create_notifications_migration_file
|
27
|
-
migration_template(
|
28
|
-
'notifications_migration.rb.erb',
|
29
|
-
'db/migrate/notification_handler_migration.rb',
|
30
|
-
migration_version: migration_version
|
31
|
-
)
|
32
|
-
end
|
33
|
-
|
34
|
-
def create_notification_model
|
35
|
-
template 'notification_model.rb', 'app/models/notification.rb'
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def migration_version
|
41
|
-
return unless Rails.version >= '5.0.0'
|
42
|
-
|
43
|
-
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
NotificationHandler.configure do |config|
|
4
|
-
# Cache amount of unread and read notifications for notification targets.
|
5
|
-
# Learn more: https://github.com/jonhue/notifications-rails/tree/master/notification-handler#caching
|
6
|
-
# config.cache = false
|
7
|
-
|
8
|
-
# Groups are a powerful way to bulk-create notifications for multiple objects
|
9
|
-
# that don't necessarily have a common class.
|
10
|
-
# Learn more: https://github.com/jonhue/notifications-rails/tree/master/notification-handler#groups
|
11
|
-
# config.define_group :subscribers, -> { User.where(subscriber: true) }
|
12
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class NotificationHandlerMigration < ActiveRecord::Migration<%= migration_version %>
|
4
|
-
def change
|
5
|
-
create_table :notifications do |t|
|
6
|
-
t.references :target, polymorphic: true, index: true
|
7
|
-
t.references :object, polymorphic: true, index: true
|
8
|
-
|
9
|
-
t.boolean :read, default: false, null: false, index: true
|
10
|
-
|
11
|
-
t.text :metadata
|
12
|
-
|
13
|
-
t.timestamps
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/lib/notification-handler.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module NotificationHandler
|
4
|
-
require_relative 'notification_handler/configuration'
|
5
|
-
|
6
|
-
require_relative 'notification_handler/engine'
|
7
|
-
|
8
|
-
autoload :Group, 'notification_handler/group'
|
9
|
-
|
10
|
-
autoload :Target, 'notification_handler/target'
|
11
|
-
autoload :Object, 'notification_handler/object'
|
12
|
-
autoload :NotificationLib, 'notification_handler/notification_lib'
|
13
|
-
autoload :NotificationScopes, 'notification_handler/notification_scopes'
|
14
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'group'
|
4
|
-
|
5
|
-
module NotificationHandler
|
6
|
-
class << self
|
7
|
-
attr_writer :configuration
|
8
|
-
|
9
|
-
def configuration
|
10
|
-
@configuration ||= Configuration.new
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.configure
|
15
|
-
yield configuration
|
16
|
-
end
|
17
|
-
|
18
|
-
class Configuration
|
19
|
-
attr_accessor :groups
|
20
|
-
attr_accessor :cache
|
21
|
-
|
22
|
-
def initialize
|
23
|
-
@groups = {}
|
24
|
-
@cache = false
|
25
|
-
end
|
26
|
-
|
27
|
-
def define_group(name, target_scope)
|
28
|
-
groups[name.to_sym] = ::NotificationHandler::Group.new(target_scope)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/engine'
|
4
|
-
require 'active_record'
|
5
|
-
|
6
|
-
module NotificationHandler
|
7
|
-
class Engine < ::Rails::Engine
|
8
|
-
initializer 'notification-handler.active_record' do
|
9
|
-
ActiveSupport.on_load :active_record do
|
10
|
-
include NotificationHandler::Target
|
11
|
-
include NotificationHandler::Object
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module NotificationHandler
|
4
|
-
class Group
|
5
|
-
attr_reader :target_scope
|
6
|
-
|
7
|
-
def initialize(target_scope)
|
8
|
-
@target_scope = target_scope
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.find_by_name(name)
|
12
|
-
NotificationHandler.configuration.groups[name]
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.find_by_name!(name)
|
16
|
-
find_by_name(name) ||
|
17
|
-
raise(ArgumentError,
|
18
|
-
"Could not find a registered group for #{name}. " \
|
19
|
-
"Make sure you register it with config.define_group :#{name}")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support'
|
4
|
-
|
5
|
-
module NotificationHandler
|
6
|
-
module NotificationLib
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
included do
|
10
|
-
self.inheritance_column = :_type_disabled
|
11
|
-
|
12
|
-
after_commit :cache
|
13
|
-
|
14
|
-
serialize :metadata, Hash
|
15
|
-
|
16
|
-
belongs_to :target, polymorphic: true
|
17
|
-
belongs_to :object, polymorphic: true, optional: true
|
18
|
-
|
19
|
-
include NotificationHandler::NotificationLib::InstanceMethods
|
20
|
-
|
21
|
-
if defined?(NotificationRenderer)
|
22
|
-
include NotificationRenderer::NotificationLib
|
23
|
-
end
|
24
|
-
if defined?(NotificationPusher)
|
25
|
-
include NotificationPusher::NotificationLib
|
26
|
-
end
|
27
|
-
if defined?(NotificationSettings)
|
28
|
-
include NotificationSettings::NotificationLib
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
module ClassMethods
|
33
|
-
def for_group(group, args: [], attrs: {})
|
34
|
-
return if group.nil?
|
35
|
-
|
36
|
-
target_scope = NotificationHandler::Group.find_by_name!(group)
|
37
|
-
.target_scope
|
38
|
-
target_scope.call(*args)&.map do |target|
|
39
|
-
Notification.create(attrs.merge(target: target))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
module InstanceMethods
|
45
|
-
def read?
|
46
|
-
read
|
47
|
-
end
|
48
|
-
|
49
|
-
def unread?
|
50
|
-
!read
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def cache
|
56
|
-
return unless read_changed?
|
57
|
-
|
58
|
-
target.read_notification_count = target.notifications.read.size
|
59
|
-
target.unread_notification_count = target.notifications.unread.size
|
60
|
-
target.save!
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support'
|
4
|
-
|
5
|
-
module NotificationHandler
|
6
|
-
module NotificationScopes
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
included do
|
10
|
-
scope :read, -> { where(read: true) }
|
11
|
-
scope :unread, -> { where(read: false) }
|
12
|
-
|
13
|
-
if defined?(NotificationRenderer)
|
14
|
-
include NotificationRenderer::NotificationScopes
|
15
|
-
end
|
16
|
-
if defined?(NotificationSettings)
|
17
|
-
include NotificationSettings::NotificationScopes
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support'
|
4
|
-
|
5
|
-
module NotificationHandler
|
6
|
-
module Object
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
included do
|
10
|
-
def self.notification_object
|
11
|
-
has_many :belonging_notifications,
|
12
|
-
as: :object, class_name: 'Notification', dependent: :destroy
|
13
|
-
|
14
|
-
# rubocop:disable Style/GuardClause
|
15
|
-
if defined?(NotificationSettings)
|
16
|
-
include NotificationSettings::Subscribable
|
17
|
-
end
|
18
|
-
# rubocop:enable Style/GuardClause
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support'
|
4
|
-
|
5
|
-
module NotificationHandler
|
6
|
-
module Target
|
7
|
-
extend ActiveSupport::Concern
|
8
|
-
|
9
|
-
included do
|
10
|
-
def self.notification_target
|
11
|
-
has_many :notifications, as: :target, dependent: :destroy
|
12
|
-
include NotificationHandler::Target::InstanceMethods
|
13
|
-
|
14
|
-
include NotificationSettings::Target if defined?(NotificationSettings)
|
15
|
-
# rubocop:disable Style/GuardClause
|
16
|
-
if defined?(NotificationSettings)
|
17
|
-
include NotificationSettings::Subscriber
|
18
|
-
end
|
19
|
-
# rubocop:enable Style/GuardClause
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module InstanceMethods
|
24
|
-
def notify(options = {})
|
25
|
-
notifications.create(options)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|