notification-handler 1.2.4 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc489d8f6080f6cc7466aa6214ef5cbc6ec3f54eae6097a54a28067419f05b3e
4
- data.tar.gz: a8720f97a522522ed584cc6582f4ef7d8001d52704a973f8d6d032433ef6aff9
3
+ metadata.gz: 44da09c04b6282f1d6eba56e5a195858d5646964e5e7f6e1ee47eda4252d7df2
4
+ data.tar.gz: acbc2f716492d9450c40d294c91b3a6145e9520bc4a3c942211d9e3f7df668b4
5
5
  SHA512:
6
- metadata.gz: 48aa1cb7d557c1501b9c2d58e900fb097064eabdce54a87029bffdd6d1d8623baaf2b5c6611817e61529a5a49819ae4c37cfbe4976d527b9b8a09682ca5a4df1
7
- data.tar.gz: a73dce232acf9b9e3dd84e59fd4a9ce9ddad39606603ae6d4a88209e4677a93f7f8c1782ef392243f9273cbf27c165f249a58b19b8fc2fe81f366de7fd4369f4
6
+ metadata.gz: 41d91481c7d251290aa7c3a12cec7cfa778f74aeb579a3ea7224a3e3947c9736aa0fe8d339d3ec5af16492391c41828d50384b37ab976eff004d842ffe78e5ea
7
+ data.tar.gz: f658cb7133391ac215459a7831b50a6280a4d4aa2e9c2f3d8541725749154197663eec3d83050b27f80a3805fc7bd7c3a8cbcefeed33ce3fee8ba680ece76f3e
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2017 Jonas Hübotter
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Jonas Hübotter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,260 +1,84 @@
1
- # NotificationHandler
2
-
3
- [![Gem Version](https://badge.fury.io/rb/notification-handler.svg)](https://badge.fury.io/rb/notification-handler) <img src="https://travis-ci.org/jonhue/notifications-rails.svg?branch=master" />
4
-
5
- Create and modify your notifications through a simple API.
6
-
7
- ---
8
-
9
- ## Table of Contents
10
-
11
- * [Installation](#installation)
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
- * [Contributors](#contributors)
24
- * [Semantic versioning](#semantic-versioning)
25
- * [License](#license)
26
-
27
- ---
28
-
29
- ## Installation
30
-
31
- NotificationHandler works with Rails 5 onwards. You can add it to your `Gemfile` with:
32
-
33
- ```ruby
34
- gem 'notification-handler'
35
- ```
36
-
37
- And then execute:
38
-
39
- $ bundle
40
-
41
- Or install it yourself as:
42
-
43
- $ gem install notification-handler
44
-
45
- If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
46
-
47
- ```ruby
48
- gem 'notification-handler', github: 'jonhue/notifications-rails'
49
- ```
50
-
51
- Now run the generator:
52
-
53
- $ rails g notification_handler:install
54
-
55
- To wrap things up, migrate the changes to your database:
56
-
57
- $ rails db:migrate
58
-
59
- ---
60
-
61
- ## Usage
62
-
63
- ### `Notification` API
64
-
65
- You can use all the ActiveRecord methods you know and love on your `Notification` class. So creating a new notification is dead simple:
66
-
67
- ```ruby
68
- notification = Notification.new
69
- ```
70
-
71
- 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:
72
-
73
- ```ruby
74
- notification.target = User.first
75
- ```
76
-
77
- To store information in your `Notification` record you can use the `metadata` attribute that gets serialized as a `Hash`:
78
-
79
- ```ruby
80
- notification.metadata = {
81
- title: 'My first notification',
82
- content: "It looks great, doesn't it?"
83
- }
84
- ```
85
-
86
- Another form of adding information is by associating an object to the notification. This can be a record of any class you like:
87
-
88
- ```ruby
89
- notification.object = Recipe.first
90
- ```
91
-
92
- The `read` attribute determines whether a notification has been seen or not:
93
-
94
- ```ruby
95
- notification.read = true
96
- notification.read? # true
97
- notification.unread? # false
98
- ```
99
-
100
- You can use scopes to filter for read or unread notifications:
101
-
102
- ```ruby
103
- # Return all read notifications
104
- Notification.read
105
-
106
- # Return all unread notifications
107
- Notification.unread
108
-
109
- # Number of unread notifications
110
- Notification.unread.count
111
- ```
112
-
113
- ### `notification_target`
114
-
115
- To use records of an ActiveRecord class as notification targets, add the following to your class:
116
-
117
- ```ruby
118
- class User < ApplicationRecord
119
- notification_target
120
- end
121
- ```
122
-
123
- Now belonging notifications are easy to access:
124
-
125
- ```ruby
126
- notifications = User.first.notifications
127
- ```
128
-
129
- You can create a notification from a `target`:
130
-
131
- ```ruby
132
- User.first.notify object: Recipe.first
133
- ```
134
-
135
- ...
136
-
137
- ### `notification_object`
138
-
139
- When using records of an ActiveRecord class as notification objects, add this to your class:
140
-
141
- ```ruby
142
- class Recipe < ApplicationRecord
143
- notification_object
144
- end
145
- ```
146
-
147
- Now associated notifications are easy to access:
148
-
149
- ```ruby
150
- notifications = Recipe.first.belonging_notifications
151
- ```
152
-
153
- ...
154
-
155
- ### Groups
156
-
157
- Groups are a powerful way to bulk-create notifications for multiple objects that don't necessarily have a common class.
158
-
159
- #### Defining a group
160
-
161
- You define groups in your `NotificationHandler` configuration:
162
-
163
- ```ruby
164
- NotificationHandler.configure do |config|
165
- config.define_group :subscribers, User.where(subscriber: true)
166
- end
167
- ```
168
-
169
- When creating a notification for the group `:subscribers`, one notification will be added for every target that fulfills this scope: `User.where(subscriber: true)`. You can also target objects from different classes:
170
-
171
- ```ruby
172
- NotificationHandler.configure do |config|
173
- config.define_group :subscribers, User.where(subscriber: true) + Admin.all
174
- end
175
- ```
176
-
177
- #### Using a group
178
-
179
- Bulk-creation of notifications for a certain group is fairly simple:
180
-
181
- ```ruby
182
- notification = Notification.create object: Recipe.first, group: :subscribers
183
- ```
184
-
185
- **Note:** You are not able to set the `target` attribute when a `group` has been specified.
186
-
187
- ### Caching
188
-
189
- You can cache the amount of unread and read notifications for notification targets by settings the [`cache`](#configuration) configuration option to `true`.
190
-
191
- Then add the following columns to the database tables of ActiveRecord classes acting as notification targets:
192
-
193
- ```ruby
194
- add_column :user, :read_notification_count, :integer
195
- add_column :user, :unread_notification_count, :integer
196
- ```
197
-
198
- ---
199
-
200
- ## Configuration
201
-
202
- You can configure NotificationHandler by passing a block to `configure`. This can be done in `config/initializers/notification-handler.rb`:
203
-
204
- ```ruby
205
- NotificationHandler.configure do |config|
206
- config.cache = true
207
- end
208
- ```
209
-
210
- **`cache`** Cache amount of unread and read notifications for notification targets. Takes a boolean. Defaults to `false`.
211
-
212
- ---
213
-
214
- ## To Do
215
-
216
- [Here](https://github.com/jonhue/notifications-rails/projects/2) is the full list of current projects.
217
-
218
- To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/notifications-rails/issues/new).
219
-
220
- ---
221
-
222
- ## Contributing
223
-
224
- We hope that you will consider contributing to NotificationHandler. Please read this short overview for some information about how to get started:
225
-
226
- [Learn more about contributing to this repository](https://github.com/jonhue/notifications-rails/blob/master/CONTRIBUTING.md), [Code of Conduct](https://github.com/jonhue/notifications-rails/blob/master/CODE_OF_CONDUCT.md)
227
-
228
- ### Contributors
229
-
230
- Give the people some :heart: who are working on this project. See them all at:
231
-
232
- https://github.com/jonhue/notifications-rails/graphs/contributors
233
-
234
- ### Semantic Versioning
235
-
236
- NotificationHandler follows Semantic Versioning 2.0 as defined at http://semver.org.
237
-
238
- ## License
239
-
240
- MIT License
241
-
242
- Copyright (c) 2017 Jonas Hübotter
243
-
244
- Permission is hereby granted, free of charge, to any person obtaining a copy
245
- of this software and associated documentation files (the "Software"), to deal
246
- in the Software without restriction, including without limitation the rights
247
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
248
- copies of the Software, and to permit persons to whom the Software is
249
- furnished to do so, subject to the following conditions:
250
-
251
- The above copyright notice and this permission notice shall be included in all
252
- copies or substantial portions of the Software.
253
-
254
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
255
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
256
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
257
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
258
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
259
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
260
- SOFTWARE.
1
+ # notifications-rails
2
+
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
+
5
+ ## Philosophy
6
+
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
+
9
+ **[notification-handler](notification-handler):** Create and modify your notifications through a simple API.
10
+
11
+ **[notification-renderer](notification-renderer):** Render your notifications in various contexts.
12
+
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).
14
+
15
+ **[notification-settings](notification-settings):** Integrates with your authentication solution to craft a personalized user notification platform.
16
+
17
+ You may just use the components you actually need, or instead use this gem to bundle everything for a complete notification solution.
18
+
19
+ ## Installation
20
+
21
+ You can add notifications-rails to your `Gemfile` with:
22
+
23
+ ```ruby
24
+ gem 'notifications-rails'
25
+ ```
26
+
27
+ And then run:
28
+
29
+ $ bundle install
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install notifications-rails
34
+
35
+ If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
36
+
37
+ ```ruby
38
+ gem 'notifications-rails', github: 'jonhue/notifications-rails'
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ Details on usage are provided in the [documentation](#philosophy) of the specific modules.
44
+
45
+ ## Development
46
+
47
+ To start development you first have to fork this repository and locally clone your fork.
48
+
49
+ Install the projects dependencies by running:
50
+
51
+ $ bundle install
52
+
53
+ ### Testing
54
+
55
+ Tests are written with RSpec. Integration tests are located in `/spec`, unit tests can be found in `<module>/spec`.
56
+
57
+ To run all tests:
58
+
59
+ $ ./rspec
60
+
61
+ To run RuboCop:
62
+
63
+ $ bundle exec rubocop
64
+
65
+ You can find all commands run by the CI workflow in `.github/workflows/ci.yml`.
66
+
67
+ ## Contributing
68
+
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).
70
+
71
+ ## Releases
72
+
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).
74
+
75
+ notifications-rails follows Semantic Versioning 2.0 as defined at http://semver.org. Reference our [security policy](SECURITY.md).
76
+
77
+ ### Publishing
78
+
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.
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'notification-handler'
4
+ require 'notification-renderer'
5
+ require 'notification-pusher'
6
+ require 'notification-settings'
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notification-handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
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: 2018-03-17 00:00:00.000000000 Z
11
+ date: 2020-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: railties
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: activerecord
28
+ name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: activesupport
42
+ name: railties
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,61 +53,117 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: factory_bot
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '3.7'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '3.7'
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: rubocop
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
- - - "~>"
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: sqlite3
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
74
144
  - !ruby/object:Gem::Version
75
- version: '0.52'
145
+ version: '0'
76
146
  type: :development
77
147
  prerelease: false
78
148
  version_requirements: !ruby/object:Gem::Requirement
79
149
  requirements:
80
- - - "~>"
150
+ - - ">="
81
151
  - !ruby/object:Gem::Version
82
- version: '0.52'
152
+ version: '0'
83
153
  description: Create and modify your notifications through a simple API.
84
- email: me@jonhue.me
154
+ email: jonas.huebotter@gmail.com
85
155
  executables: []
86
156
  extensions: []
87
157
  extra_rdoc_files: []
88
158
  files:
89
- - CHANGELOG.md
90
159
  - LICENSE
91
160
  - README.md
92
- - app/models/notification_handler/notification.rb
93
- - lib/generators/notification_handler/install_generator.rb
94
- - lib/generators/templates/install/README.md
95
- - lib/generators/templates/install/initializer.rb
96
- - lib/generators/templates/install/notification_model.rb
97
- - lib/generators/templates/install/notifications_migration.rb.erb
98
- - lib/notification-handler.rb
99
- - lib/notification_handler/configuration.rb
100
- - lib/notification_handler/engine.rb
101
- - lib/notification_handler/group.rb
102
- - lib/notification_handler/notification_library.rb
103
- - lib/notification_handler/notification_scopes.rb
104
- - lib/notification_handler/object.rb
105
- - lib/notification_handler/railtie.rb
106
- - lib/notification_handler/target.rb
161
+ - lib/notifications-rails.rb
107
162
  homepage: https://github.com/jonhue/notifications-rails/tree/master/notification-handler
108
163
  licenses:
109
164
  - MIT
110
- metadata: {}
165
+ metadata:
166
+ github_repo: ssh://github.com/jonhue/notifications-rails
111
167
  post_install_message:
112
168
  rdoc_options: []
113
169
  require_paths:
@@ -116,15 +172,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
172
  requirements:
117
173
  - - ">="
118
174
  - !ruby/object:Gem::Version
119
- version: '2.3'
175
+ version: 2.2.2
120
176
  required_rubygems_version: !ruby/object:Gem::Requirement
121
177
  requirements:
122
178
  - - ">="
123
179
  - !ruby/object:Gem::Version
124
180
  version: '0'
125
181
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.7.4
182
+ rubygems_version: 3.1.4
128
183
  signing_key:
129
184
  specification_version: 4
130
185
  summary: Create and modify your notifications through a simple API
@@ -1,51 +0,0 @@
1
- # Changelog
2
-
3
- ### master
4
-
5
- * nothing yet
6
-
7
- ### 1.2.3 - 2018/01/23
8
-
9
- * bugfixes
10
- * removed ActiveRecord STI from `Notification` model
11
-
12
- ### 1.0.0 - 2017/12/28
13
-
14
- * bugfixes
15
-
16
- ### 1.0.0.beta6 - 2017/12/28
17
-
18
- * bugfixes
19
- * fix lib loading problems
20
-
21
- ### 1.0.0.beta5 - 2017/12/28
22
-
23
- * bugfixes
24
- * fix generators
25
- * fix lib loading problems
26
- * fix syntax errors
27
-
28
- ### 1.0.0.beta4 - 2017/12/27
29
-
30
- * features
31
- * add caching functionality
32
- * add `read` attribute to `Notification` instances
33
- * add `notify` method to notification targets
34
-
35
- ### 1.0.0.beta3 - 2017/12/25
36
-
37
- * features
38
- * allow `Group` object definition in configuration
39
-
40
- ### 1.0.0.beta2 - 2017/12/23
41
-
42
- * features
43
- * add `NotificationHandler::Group` class for target grouping notifications
44
- * add `metadata` hash to `Notification` objects
45
- * enhancements
46
- * add custom `NotificationHandler::Notification` class
47
- * drop Rails dependency
48
-
49
- ### 1.0.0.beta1 - 2017/12/22
50
-
51
- * initial release
@@ -1,6 +0,0 @@
1
- class NotificationHandler::Notification < ApplicationRecord
2
-
3
- include NotificationHandler::NotificationLibrary
4
- include NotificationHandler::NotificationScopes
5
-
6
- end
@@ -1,46 +0,0 @@
1
- require 'rails/generators'
2
- require 'rails/generators/migration'
3
-
4
- module NotificationHandler
5
-
6
- class InstallGenerator < Rails::Generators::Base
7
-
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
- "%.3d" % ( current_migration_number(dirname) + 1 )
18
- end
19
- end
20
-
21
- def create_initializer
22
- template 'initializer.rb', 'config/initializers/notification-handler.rb'
23
- end
24
-
25
- def create_notifications_migration_file
26
- migration_template 'notifications_migration.rb.erb', 'db/migrate/notification_handler_migration.rb', migration_version: migration_version
27
- end
28
- def create_notification_model
29
- template 'notification_model.rb', 'app/models/notification.rb'
30
- end
31
-
32
- def show_readme
33
- readme 'README.md'
34
- end
35
-
36
- private
37
-
38
- def migration_version
39
- if Rails.version >= '5.0.0'
40
- "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
41
- end
42
- end
43
-
44
- end
45
-
46
- end
@@ -1 +0,0 @@
1
- Now run `rails db:migrate` to add NotificationHandler to your database.
@@ -1,11 +0,0 @@
1
- NotificationHandler.configure do |config|
2
-
3
- # Cache amount of unread and read notifications for notification targets
4
- # Learn more: https://github.com/jonhue/notifications-rails/tree/master/notification-handler#caching
5
- # config.cache = false
6
-
7
- # Groups are a powerful way to bulk-create notifications for multiple objects that don't necessarily have a common class.
8
- # Learn more: https://github.com/jonhue/notifications-rails/tree/master/notification-handler#groups
9
- # config.define_group :subscribers, User.where(subscriber: true)
10
-
11
- end
@@ -1,2 +0,0 @@
1
- class Notification < NotificationHandler::Notification
2
- end
@@ -1,16 +0,0 @@
1
- class NotificationHandlerMigration < ActiveRecord::Migration<%= migration_version %>
2
- def change
3
- create_table :notifications do |t|
4
-
5
- t.references :target, polymorphic: true, index: true
6
- t.references :object, polymorphic: true, index: true
7
-
8
- t.boolean :read, default: false, null: false, index: true
9
-
10
- t.text :metadata
11
-
12
- t.timestamps
13
-
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module NotificationHandler
2
-
3
- require 'notification_handler/configuration'
4
-
5
- require 'notification_handler/engine'
6
-
7
- autoload :Group, 'notification_handler/group'
8
-
9
- autoload :Target, 'notification_handler/target'
10
- autoload :Object, 'notification_handler/object'
11
- autoload :NotificationLibrary, 'notification_handler/notification_library'
12
- autoload :NotificationScopes, 'notification_handler/notification_scopes'
13
-
14
- require 'notification_handler/railtie'
15
-
16
- end
@@ -1,28 +0,0 @@
1
- module NotificationHandler
2
-
3
- class << self
4
- attr_accessor :configuration
5
- end
6
-
7
- def self.configure
8
- self.configuration ||= Configuration.new
9
- yield configuration
10
- end
11
-
12
- class Configuration
13
-
14
- attr_accessor :groups
15
- attr_accessor :cache
16
-
17
- def initialize
18
- @groups = []
19
- @cache = false
20
- end
21
-
22
- def define_group name, target_scope
23
- self.groups << ::NotificationHandler::Group.new(name.to_sym, target_scope)
24
- end
25
-
26
- end
27
-
28
- end
@@ -1,7 +0,0 @@
1
- require 'rails/railtie'
2
- require 'active_record'
3
-
4
- module NotificationHandler
5
- class Engine < ::Rails::Engine
6
- end
7
- end
@@ -1,17 +0,0 @@
1
- module NotificationHandler
2
- class Group
3
-
4
- attr_accessor :name
5
- attr_accessor :target_scope
6
-
7
- def initialize name, target_scope
8
- @name = name
9
- @target_scope = target_scope
10
- end
11
-
12
- def self.find_by_name name
13
- NotificationHandler.configuration.groups.select { |group| group.name == name.to_sym }
14
- end
15
-
16
- end
17
- end
@@ -1,62 +0,0 @@
1
- require 'active_support'
2
-
3
- module NotificationHandler
4
- module NotificationLibrary
5
-
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- self.inheritance_column = :_type_disabled
10
-
11
- before_validation :create_for_group
12
- after_commit :cache
13
-
14
- serialize :metadata, Hash
15
- attr_accessor :group
16
-
17
- belongs_to :target, polymorphic: true
18
- belongs_to :object, polymorphic: true, optional: true
19
-
20
- include NotificationHandler::NotificationLibrary::InstanceMethods
21
-
22
- include NotificationRenderer::NotificationLibrary if defined?(NotificationRenderer)
23
- include NotificationPusher::NotificationLibrary if defined?(NotificationPusher)
24
- include NotificationSettings::NotificationLibrary if defined?(NotificationSettings)
25
- end
26
-
27
- module InstanceMethods
28
-
29
- def read?
30
- self.read
31
- end
32
- def unread?
33
- !self.read
34
- end
35
-
36
- private
37
-
38
- def create_for_group
39
- unless self.group.nil?
40
- target_scope = NotificationHandler::Group.find_by_name(self.group).last.target_scope
41
- target_scope&.each do |target|
42
- notification = self.dup
43
- notification.target = target
44
- notification.group = nil
45
- notification.save
46
- end
47
- return false
48
- end
49
- end
50
-
51
- def cache
52
- if self.read_changed?
53
- self.target.read_notification_count = self.target.notifications.read.count
54
- self.target.unread_notification_count = self.target.notifications.unread.count
55
- self.target.save!
56
- end
57
- end
58
-
59
- end
60
-
61
- end
62
- end
@@ -1,17 +0,0 @@
1
- require 'active_support'
2
-
3
- module NotificationHandler
4
- module NotificationScopes
5
-
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- scope :read, -> { where(read: true) }
10
- scope :unread, -> { where(read: false) }
11
-
12
- include NotificationRenderer::NotificationScopes if defined?(NotificationRenderer)
13
- include NotificationSettings::NotificationScopes if defined?(NotificationSettings)
14
- end
15
-
16
- end
17
- end
@@ -1,24 +0,0 @@
1
- module NotificationHandler
2
- module Object
3
-
4
- def self.included base
5
- base.extend ClassMethods
6
- end
7
-
8
- module ClassMethods
9
- def notification_object
10
- has_many :belonging_notifications, as: :object, class_name: 'Notification', dependent: :destroy
11
- include NotificationHandler::Object::InstanceMethods
12
-
13
- include NotificationSettings::Subscribable if defined?(NotificationSettings)
14
- end
15
- end
16
-
17
- module InstanceMethods
18
-
19
- # ...
20
-
21
- end
22
-
23
- end
24
- end
@@ -1,16 +0,0 @@
1
- require 'rails/railtie'
2
- require 'active_record'
3
- require 'active_support'
4
-
5
- module NotificationHandler
6
- class Railtie < Rails::Railtie
7
-
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
-
15
- end
16
- end
@@ -1,27 +0,0 @@
1
- module NotificationHandler
2
- module Target
3
-
4
- def self.included base
5
- base.extend ClassMethods
6
- end
7
-
8
- module ClassMethods
9
- def notification_target
10
- has_many :notifications, as: :target, dependent: :destroy
11
- include NotificationHandler::Target::InstanceMethods
12
-
13
- include NotificationSettings::Target if defined?(NotificationSettings)
14
- include NotificationSettings::Subscriber if defined?(NotificationSettings)
15
- end
16
- end
17
-
18
- module InstanceMethods
19
-
20
- def notify options = {}
21
- self.notifications.create options
22
- end
23
-
24
- end
25
-
26
- end
27
- end