notification-renderer 2.0.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa29639e71ac1a9870c14071d6274bbd507de189a2c0ebac9a804d307577b510
4
- data.tar.gz: 61c2c695bc2ad340a9ad7b2ecfd6bf3d966cc7c81af59d7b2de997dbe9617437
3
+ metadata.gz: c9180b03296da9fe22d02dbae27103fcfe02bf909e81d26ff32b21c826983df2
4
+ data.tar.gz: f1f91500df8c82299198dfc7d954d6fde9a2b007b3259e272809ff3970098606
5
5
  SHA512:
6
- metadata.gz: 7865d41597d2d06299ee574f811212a2425533053cd2b9819d50612810ca11997225e66f11e8bb2f762024f94d852d8243224fd3eade3944ef2edc2e41b85d24
7
- data.tar.gz: f4756a6497785dc4ee3e0964236d91429193cc03b4265d14f4d5c2c2f6e51543367276c626c1d27eded96c48b02dbfa5288892c7ac2f686df6795b87b768ff03
6
+ metadata.gz: 6c7fd5f4be251ee7b855e44cc5396307bc592e10976fff5a738fb51653d7121088a5f624f74ed23c1cd74340dc140637daa0308a22a6db0613e3ed2f979e59f9
7
+ data.tar.gz: 790b963ad2ed742a30d15715ed8edd41ecdecc99dd9355a627422d2c4aac4b120271ed3aeb8ec23a3b9a3f1d467c9f4c091e8ba5cb9ca931645c55e03470012b
data/README.md CHANGED
@@ -1,290 +1,84 @@
1
- # NotificationRenderer
1
+ # notifications-rails
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/notification-renderer.svg)](https://badge.fury.io/rb/notification-renderer) ![Travis](https://travis-ci.com/jonhue/notifications-rails.svg?branch=master)
3
+ A flexible notification library supporting the delivery to external services, rendering in various environments, and user configuration by category.
4
4
 
5
- Render your notifications on multiple platforms by specifying notification types.
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
- ## Table of Contents
9
+ **[notification-handler](notification-handler):** Create and modify your notifications through a simple API.
10
10
 
11
- * [Installation](#installation)
12
- * [Usage](#usage)
13
- * [Types](#types)
14
- * [Generating a new type](#generating-a-new-type)
15
- * [Using a type](#using-a-type)
16
- * [Renderers](#renderers)
17
- * [View helpers](#view-helpers)
18
- * [`render_notification`](#render_notification)
19
- * [`render_notifications`](#render_notifications)
20
- * [Grouping](#grouping)
21
- * [Grouping by notification types](#grouping-by-notification-types)
22
- * [Grouping by notification dates](#grouping-by-notification-dates)
23
- * [Configuration](#configuration)
24
- * [To Do](#to-do)
25
- * [Contributing](#contributing)
26
- * [Semantic versioning](#semantic-versioning)
11
+ **[notification-renderer](notification-renderer):** Render your notifications in various contexts.
27
12
 
28
- ---
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).
29
14
 
30
- ## Installation
31
-
32
- NotificationRenderer works with Rails 5 onwards. You can add it to your `Gemfile` with:
33
-
34
- ```ruby
35
- gem 'notification-renderer'
36
- ```
37
-
38
- And then execute:
39
-
40
- $ bundle
41
-
42
- Or install it yourself as:
43
-
44
- $ gem install notification-renderer
45
-
46
- Now run the generator:
47
-
48
- $ rails g notification_renderer:install
49
-
50
- To wrap things up, migrate the changes to your database:
51
-
52
- $ rails db:migrate
53
-
54
- ---
55
-
56
- ## Usage
57
-
58
- ### Types
59
-
60
- NotificationRenderer uses templates to render your notifications.
61
-
62
- The `type` of a notification determines which template gets utilized for rendering. Each notification type has multiple templates each of which responsible for rendering a notification in another scenario. The default template for a given type is `index`.
63
-
64
- #### Generating a new type
65
-
66
- This gem comes with a generator to make adding new types a whole lot easier. Run in your terminal:
67
-
68
- $ rails g notification_renderer:type -t notification
69
-
70
- This will create the following structure in your application:
71
-
72
- * `views`
73
- * `notifications`
74
- * `notification`
75
- * `_index.html.erb`
15
+ **[notification-settings](notification-settings):** Integrates with your authentication solution to craft a personalized user notification platform.
76
16
 
77
- You can also customize the generated templates (renderers):
17
+ You may just use the components you actually need, or instead use this gem to bundle everything for a complete notification solution.
78
18
 
79
- $ rails g notification_renderer:type -t notification -r index feed
80
-
81
- This command will also create a custom renderer called `feed` for the notification type `notification`:
82
-
83
- * `views`
84
- * `notifications`
85
- * `notification`
86
- * `_feed.html.erb`
87
- * `_index.html.erb`
88
-
89
- #### Using a type
90
-
91
- You are able to specify the `type` of a `Notification` record:
92
-
93
- ```ruby
94
- notification = Notification.create(target: User.first, object: Recipe.first, type: 'notification')
95
- ```
96
-
97
- **Note:** The `type` attribute of any new `Notification` record will default to the [`default_type` configuration](#configuration).
19
+ ## Installation
98
20
 
99
- You can also scope records by their type:
21
+ You can add notifications-rails to your `Gemfile` with:
100
22
 
101
23
  ```ruby
102
- # Return records with `'notification'` as type
103
- Notification.notification_type
104
-
105
- # Return records with `'follow'` as type
106
- Notification.follow_type
107
- ```
108
-
109
- ### Renderers
110
-
111
- In your renderers you can access the `Notification` record through the `notification` variable. This is how a renderer could look like:
112
-
113
- ```erb
114
- <%= notification.target.name %> commented on <%= notification.object.article.title %>.
115
- ```
116
-
117
- ### View helpers
118
-
119
- NotificationRenderer introduces some view helpers to assist you in embedding notifications.
120
-
121
- #### `render_notification`
122
-
123
- `render_notification` renders a single `Notification` record:
124
-
125
- ```erb
126
- <%= render_notification Notification.first %>
127
- ```
128
-
129
- Rendering a notification will set its `read` attribute to `true`. This behavior can be [configured](#configuration).
130
-
131
- You can also specify a renderer. It defaults to `'index'`.
132
-
133
- ```erb
134
- <%= render_notification Notification.first, 'feed' %>
24
+ gem 'notifications-rails'
135
25
  ```
136
26
 
137
- #### `render_notifications`
27
+ And then run:
138
28
 
139
- `render_notifications` takes an ActiveRecord array of `Notification` records and renders each of them in order:
29
+ $ bundle install
140
30
 
141
- ```erb
142
- <%= render_notifications Notification.all %>
143
- ```
144
-
145
- You can also specify a renderer. It defaults to `'index'`.
146
-
147
- ```erb
148
- <%= render_notifications Notification.all, 'feed' %>
149
- ```
150
-
151
- It wraps the rendered notifications in a `div`:
152
-
153
- ```html
154
- <div class="notification-renderer notifications">
155
- <!-- ... -->
156
- </div>
157
- ```
31
+ Or install it yourself as:
158
32
 
159
- ### Grouping
33
+ $ gem install notifications-rails
160
34
 
161
- You can group any ActiveRecord array of `Notification` records by an attribute value:
35
+ If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
162
36
 
163
37
  ```ruby
164
- Notification.all.grouping(['object.article'])
165
- Notification.all.grouping(['object.article', 'metadata[:title]'])
166
- ```
167
-
168
- **Note:** Notifications will be grouped in order.
169
-
170
- When rendering notifications you often want to group them by the object they belong to. This is how to group notifications by the associated object:
171
-
172
- ```erb
173
- <%= render_notifications_grouped Notification.all, ['object'], renderer: 'feed' %>
174
- ```
175
-
176
- You can also group notifications by nested attributes:
177
-
178
- ```erb
179
- <%= render_notifications_grouped Notification.all, ['object.article'] %>
180
- <%= render_notifications_grouped Notification.all, ['metadata[:title]'] %>
181
- ```
182
-
183
- It is also possible to group notifications for just one object:
184
-
185
- ```erb
186
- <%= render_notifications_grouped Notification.where(object_id: 1, object_type: 'Comment'), ['object'] %>
187
- ```
188
-
189
- This will render the last notification for every group and pass the attributes value grouped by to your renderer:
190
-
191
- ```erb
192
- <!-- View -->
193
-
194
- <%= render_notifications_grouped Notification.notification_type, ['object.article'] %>
195
- ```
196
-
197
- ```erb
198
- <!-- Renderer -->
199
-
200
- <% if notification_grouped? %>
201
- <%= notification.target.name %> and <%= (notifications.count - 1).to_s %> others commented on <%= attributes['object.article'].title %>.
202
- <% else %>
203
- <%= notification.target.name %> commented on <%= notification.object.article.title %>.
204
- <% end %>
205
- ```
206
-
207
- Grouping makes the following two methods available in your renderer:
208
-
209
- **`attributes`** Hash of attributes grouped by and their values.
210
-
211
- **`notifications`** The ActiveRecord array of notifications including the currently rendered notification.
212
-
213
- You may check whether a template is being used for grouping by using the `notification_grouped?` helper method.
214
-
215
- #### Grouping by notification types
216
-
217
- It is common, if rendering multiple notification types at once, to group the notifications by their type:
218
-
219
- ```erb
220
- <%= render_notifications_grouped Notification.all, ['object.article'], group_by_type: true %>
221
- ```
222
-
223
- This is identical to the following:
224
-
225
- ```erb
226
- <%= render_notifications_grouped Notification.all, [:type, 'object.article'] %>
38
+ gem 'notifications-rails', github: 'jonhue/notifications-rails'
227
39
  ```
228
40
 
229
- #### Grouping by notification dates
230
-
231
- It is also often required to group notifications by their date of creation:
232
-
233
- ```erb
234
- <%= render_notifications_grouped Notification.all, ['object.article'], group_by_date: :month %>
235
- ```
236
-
237
- This is identical to the following:
238
-
239
- ```erb
240
- <%= render_notifications_grouped Notification.all, ['created_at.beginning_of_month', 'object.article'] %>
241
- ```
242
-
243
- Accepted values are:
41
+ ## Usage
244
42
 
245
- * `:minute`
246
- * `:hour`
247
- * `:day`
248
- * `:week`
249
- * `:month`
250
- * `:year`
43
+ Details on usage are provided in the [documentation](#philosophy) of the specific modules.
251
44
 
252
- **Note:** If used together with `group_by_type`, notifications will be grouped first by creation date and then by `:type`.
45
+ ## Development
253
46
 
254
- ---
47
+ To start development you first have to fork this repository and locally clone your fork.
255
48
 
256
- ## Configuration
49
+ Install the projects dependencies by running:
257
50
 
258
- You can configure NotificationRenderer by passing a block to `configure`. This can be done in `config/initializers/notification-renderer.rb`:
51
+ $ bundle install
259
52
 
260
- ```ruby
261
- NotificationRenderer.configure do |config|
262
- config.default_type = 'notification'
263
- end
264
- ```
53
+ ### Testing
265
54
 
266
- **`default_type`** Choose your default notification type. Takes a string. Defaults to `'notification'`.
55
+ Tests are written with RSpec. Integration tests are located in `/spec`, unit tests can be found in `<module>/spec`.
267
56
 
268
- **`default_renderer`** Choose your default renderer. Takes a string. Defaults to `'index'`.
57
+ To run all tests:
269
58
 
270
- **`auto_read`** Automatically mark rendered notifications as read. Takes a boolean. Defaults to `true`.
59
+ $ ./rspec
271
60
 
272
- ---
61
+ To run RuboCop:
273
62
 
274
- ## To Do
63
+ $ bundle exec rubocop
275
64
 
276
- We use [GitHub projects](https://github.com/jonhue/notifications-rails/projects/7) to coordinate the work on this project.
65
+ You can find all commands run by the CI workflow in `.github/workflows/ci.yml`.
277
66
 
278
- To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/notifications-rails/issues/new).
67
+ ## Contributing
279
68
 
280
- ---
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).
281
70
 
282
- ## Contributing
71
+ ## Releases
283
72
 
284
- We hope that you will consider contributing to NotificationRenderer. Please read this short overview for some information about how to get started:
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).
285
74
 
286
- [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)
75
+ notifications-rails follows Semantic Versioning 2.0 as defined at http://semver.org. Reference our [security policy](SECURITY.md).
287
76
 
288
- ### Semantic Versioning
77
+ ### Publishing
289
78
 
290
- NotificationRenderer follows Semantic Versioning 2.0 as defined at http://semver.org.
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notification-renderer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 4.0.0
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: 2019-06-04 00:00:00.000000000 Z
11
+ date: 2022-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 2.0.0
47
+ version: 4.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 2.0.0
54
+ version: 4.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: railties
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -164,30 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
- description: Render your notifications on multiple platforms by specifying notification
168
- types.
169
- email: me@jonhue.me
167
+ description: Render your notifications in various contexts.
168
+ email: jonas.huebotter@gmail.com
170
169
  executables: []
171
170
  extensions: []
172
171
  extra_rdoc_files: []
173
172
  files:
174
173
  - LICENSE
175
174
  - README.md
176
- - app/helpers/notification_renderer_helper.rb
177
- - lib/generators/notification_renderer/install_generator.rb
178
- - lib/generators/notification_renderer/type_generator.rb
179
- - lib/generators/templates/install/initializer.rb
180
- - lib/generators/templates/install/notifications_migration.rb.erb
181
- - lib/generators/templates/type/_template.html
182
- - lib/notification-renderer.rb
183
- - lib/notification_renderer/configuration.rb
184
- - lib/notification_renderer/engine.rb
185
- - lib/notification_renderer/notification_lib.rb
186
- - lib/notification_renderer/notification_scopes.rb
175
+ - lib/notifications-rails.rb
187
176
  homepage: https://github.com/jonhue/notifications-rails/tree/master/notification-renderer
188
177
  licenses:
189
178
  - MIT
190
- metadata: {}
179
+ metadata:
180
+ github_repo: ssh://github.com/jonhue/notifications-rails
191
181
  post_install_message:
192
182
  rdoc_options: []
193
183
  require_paths:
@@ -196,16 +186,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
186
  requirements:
197
187
  - - ">="
198
188
  - !ruby/object:Gem::Version
199
- version: 2.2.2
189
+ version: '2.7'
200
190
  required_rubygems_version: !ruby/object:Gem::Requirement
201
191
  requirements:
202
192
  - - ">="
203
193
  - !ruby/object:Gem::Version
204
194
  version: '0'
205
195
  requirements: []
206
- rubygems_version: 3.0.3
196
+ rubygems_version: 3.3.7
207
197
  signing_key:
208
198
  specification_version: 4
209
- summary: Render your notifications on multiple platforms by specifying notification
210
- types
199
+ summary: Render your notifications in various contexts
211
200
  test_files: []
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module NotificationRendererHelper
4
- def render_notification(notification,
5
- renderer: default_renderer,
6
- attributes: nil,
7
- notifications: nil)
8
- notification.update(read: true) if auto_read
9
- render(
10
- partial: "notifications/#{notification.type}/#{renderer}",
11
- locals: {
12
- notification: notification,
13
- attributes: attributes,
14
- notifications: notifications
15
- }
16
- )
17
- end
18
-
19
- def render_notifications(notifications, renderer: default_renderer)
20
- content_tag :div, class: 'notification-renderer notifications' do
21
- notifications&.map do |notification|
22
- render_notification(notification, renderer: renderer)
23
- end
24
- end
25
- end
26
-
27
- def render_notifications_grouped(notifications, group_by,
28
- renderer: default_renderer,
29
- group_by_date: false,
30
- group_by_type: false)
31
- group_by.unshift(:type) if group_by_type
32
- if group_by_date
33
- group_by.unshift("created_at.beginning_of_#{group_by_date}")
34
- end
35
-
36
- content_tag :div, class: 'notification-renderer notifications' do
37
- recursive_notification_grouping(
38
- notifications.grouping(group_by), group_by, renderer
39
- )
40
- end
41
- end
42
-
43
- def notification_grouped?
44
- local_assigns[:attributes] && local_assigns[:notifications]
45
- end
46
-
47
- private
48
-
49
- def recursive_notification_grouping(notifications, group_by, renderer,
50
- attributes)
51
- i = 0
52
- notifications.each do |k, v|
53
- attributes[group_by[i]] = k
54
- i += 1
55
- recursive_render_notifications_grouped(v, renderer, attributes)
56
- end
57
- end
58
-
59
- def recursive_render_notifications_grouped(notifications, renderer,
60
- attributes)
61
- if notifications.is_a?(Hash)
62
- recursive_notification_grouping(
63
- notifications, group_by, renderer, attributes
64
- )
65
- else
66
- render_notification(notifications.last,
67
- renderer: renderer,
68
- attributes: attributes,
69
- notifications: notifications)
70
- end
71
- end
72
-
73
- def auto_read
74
- NotificationRenderer.configuration.auto_read
75
- end
76
-
77
- def default_renderer
78
- NotificationRenderer.configuration.default_renderer
79
- end
80
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators'
4
- require 'rails/generators/migration'
5
-
6
- module NotificationRenderer
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 NotificationRenderer'
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('%.3d', current_migration_number(dirname) + 1)
18
- end
19
- end
20
-
21
- def create_initializer
22
- template 'initializer.rb', 'config/initializers/notification_renderer.rb'
23
- end
24
-
25
- def create_notifications_migration_file
26
- migration_template(
27
- 'notifications_migration.rb.erb',
28
- 'db/migrate/notification_renderer_migration.rb',
29
- migration_version: migration_version
30
- )
31
- end
32
-
33
- def create_templates
34
- system 'rails g notification_renderer:type -t notification'
35
- end
36
-
37
- private
38
-
39
- def migration_version
40
- return unless Rails.version >= '5.0.0'
41
-
42
- "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
43
- end
44
- end
45
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/generators'
4
- require 'rails/generators/migration'
5
-
6
- module NotificationRenderer
7
- class TypeGenerator < Rails::Generators::Base
8
- source_root(File.join(File.dirname(__FILE__), '../templates/type'))
9
- desc 'Create a new notification type'
10
- class_option :type,
11
- desc: 'Specify the notification type',
12
- type: :string,
13
- default: NotificationRenderer.configuration.default_type,
14
- aliases: '-t'
15
- class_option :renderers,
16
- desc: 'Specify the renderer templates',
17
- type: :string,
18
- default: NotificationRenderer.configuration.default_renderer,
19
- aliases: '-r'
20
-
21
- def create_templates
22
- options[:renderers].split(' ')&.each do |template|
23
- template(
24
- '_template.html',
25
- "app/views/notifications/#{options[:type]}/_#{template}.html.erb"
26
- )
27
- end
28
- end
29
- end
30
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- NotificationRenderer.configure do |config|
4
- # Choose your default notification type. Takes a string.
5
- # config.default_type = 'notification'
6
-
7
- # Choose your default renderer. Takes a string.
8
- # config.default_renderer = 'index'
9
-
10
- # Automatically mark rendered notifications as read. Takes a boolean.
11
- # config.auto_read = true
12
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class NotificationRendererMigration < ActiveRecord::Migration<%= migration_version %>
4
- def change
5
- add_column :notifications, :type, :string, index: true
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- <!--
2
- In your renderers you can access the `Notification` record through the `notification` variable. This is how a renderer could look like:
3
-
4
- <%#= notification.target.name %> commented on <%#= notification.object.article.title %>
5
-
6
- Learn more: https://github.com/jonhue/notifications-rails/tree/master/notification-renderer#renderers
7
- -->
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module NotificationRenderer
4
- require_relative 'notification_renderer/configuration'
5
-
6
- require_relative 'notification_renderer/engine'
7
-
8
- autoload :NotificationLib, 'notification_renderer/notification_lib'
9
- autoload :NotificationScopes, 'notification_renderer/notification_scopes'
10
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module NotificationRenderer
4
- class << self
5
- attr_writer :configuration
6
-
7
- def configuration
8
- @configuration ||= Configuration.new
9
- end
10
- end
11
-
12
- def self.configure
13
- yield configuration
14
- end
15
-
16
- class Configuration
17
- attr_accessor :default_type
18
- attr_accessor :default_renderer
19
- attr_accessor :auto_read
20
-
21
- def initialize
22
- @default_type = 'notification'
23
- @default_renderer = 'index'
24
- @auto_read = true
25
- end
26
- end
27
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails/engine'
4
- require 'action_view'
5
-
6
- module NotificationRenderer
7
- class Engine < ::Rails::Engine
8
- end
9
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'notification-handler'
4
- require 'active_support'
5
-
6
- module NotificationRenderer
7
- module NotificationLib
8
- extend ActiveSupport::Concern
9
-
10
- module ClassMethods
11
- def grouping(group_by)
12
- notifications = all
13
- group_by.each do |method|
14
- notifications = recursive_grouping(notifications, method)
15
- end
16
- notifications
17
- end
18
-
19
- def grouping_by(group_by)
20
- all.group_by { |notification| notification.send(group_by) }
21
- end
22
-
23
- def recursive_grouping(notifications, group_by)
24
- if notifications.is_a?(Hash)
25
- recursive_hash_grouping(notifications, group_by)
26
- else
27
- notifications.grouping_by(group_by)
28
- end
29
- notifications
30
- end
31
- end
32
-
33
- def type
34
- self[:type] || NotificationRenderer.configuration.default_type
35
- end
36
-
37
- private
38
-
39
- def recursive_hash_grouping(notifications, group_by)
40
- notifications.each_pair do |k, v|
41
- if v.is_a?(Hash)
42
- recursive_hash_grouping(v, group_by)
43
- else
44
- notifications[k] = v.grouping_by(group_by)
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'notification-handler'
4
- require 'active_support'
5
-
6
- module NotificationRenderer
7
- module NotificationScopes
8
- extend ActiveSupport::Concern
9
-
10
- module ClassMethods
11
- def method_missing(method, *args)
12
- if method.to_s[/(.+)_type/]
13
- where(type: $1.singularize.classify)
14
- else
15
- super
16
- end
17
- end
18
-
19
- def respond_to_missing?(method, include_private = false)
20
- super || method.to_s[/(.+)_type/]
21
- end
22
- end
23
- end
24
- end