noticed 1.2.15 → 1.2.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -7
- data/lib/generators/noticed/model_generator.rb +2 -2
- data/lib/noticed/base.rb +1 -1
- data/lib/noticed/delivery_methods/action_cable.rb +12 -12
- data/lib/noticed/delivery_methods/base.rb +23 -5
- data/lib/noticed/delivery_methods/email.rb +2 -6
- data/lib/noticed/model.rb +4 -4
- data/lib/noticed/translation.rb +1 -1
- data/lib/noticed/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b37e7d17da790342493c2ffc575cc5d013ac156b7ac600fb0022c79bcb034de
|
4
|
+
data.tar.gz: 87fc46cbf6829e174b0dc6df1751187965e645f7461848469e48a2ea7bcb6a46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9b4db6825f88670f27d768f40724fbd22c2f8e92fc6ce5f3bc32650cc9e77475d3c6eecb51fd7f59b10d70e735f648c92ecdae6f6d4b8ff61ff4b5c39e501d3
|
7
|
+
data.tar.gz: f474ad70283d4faa9b33bd51346acb64b29a4076b9c9c0ffcff58e60f75d331bc54b162a8e3d77310153d39caf898ac2924b234389b1089b3262b35fa7b48ac3
|
data/README.md
CHANGED
@@ -86,6 +86,7 @@ class CommentNotification < Noticed::Base
|
|
86
86
|
end
|
87
87
|
|
88
88
|
# URL helpers are accessible in notifications
|
89
|
+
# Don't forget to set your default_url_options so Rails knows how to generate urls
|
89
90
|
def url
|
90
91
|
post_path(params[:post])
|
91
92
|
end
|
@@ -113,6 +114,12 @@ You can define helper methods inside your Notification object to make it easier
|
|
113
114
|
|
114
115
|
Rails url helpers are included in notification classes by default so you have full access to them just like you would in your controllers and views.
|
115
116
|
|
117
|
+
Don't forget, you'll need to configure `default_url_options` in order for Rails to know what host and port to use when generating URLs.
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
Rails.application.routes.default_url_options[:host] = 'localhost:3000'
|
121
|
+
```
|
122
|
+
|
116
123
|
**Callbacks**
|
117
124
|
|
118
125
|
Like ActiveRecord, notifications have several different types of callbacks.
|
@@ -342,19 +349,24 @@ Delivery methods have access to the following methods and attributes:
|
|
342
349
|
|
343
350
|
#### Validating options passed to Custom Delivery methods
|
344
351
|
|
345
|
-
|
352
|
+
The presence of the delivery method options is automatically validated if using the `option(s)` method.
|
346
353
|
|
347
|
-
|
354
|
+
If you want to validate that the passed options contain valid values, or to add any custom validations, override the `self.validate!(delivery_method_options)` method from the `Noticed::DeliveryMethods::Base` class.
|
348
355
|
|
349
356
|
```ruby
|
350
357
|
class DeliveryMethods::Discord < Noticed::DeliveryMethods::Base
|
358
|
+
option :username # Requires the username option to be passed
|
359
|
+
|
351
360
|
def deliver
|
352
361
|
# Logic for sending a Discord notification
|
353
362
|
end
|
354
363
|
|
355
|
-
def self.validate!(
|
356
|
-
|
357
|
-
|
364
|
+
def self.validate!(delivery_method_options)
|
365
|
+
super # Don't forget to call super, otherwise option presence won't be validated
|
366
|
+
|
367
|
+
# Custom validations
|
368
|
+
if delivery_method_options[:username].blank?
|
369
|
+
raise Noticed::ValidationError, 'the `username` option must be present'
|
358
370
|
end
|
359
371
|
end
|
360
372
|
end
|
@@ -370,7 +382,7 @@ To fix the error, the argument has to be passed correctly. For example:
|
|
370
382
|
|
371
383
|
```ruby
|
372
384
|
class CommentNotification < Noticed::Base
|
373
|
-
deliver_by :discord, class: 'DeliveryMethods::Discord',
|
385
|
+
deliver_by :discord, class: 'DeliveryMethods::Discord', username: User.admin.username
|
374
386
|
end
|
375
387
|
```
|
376
388
|
|
@@ -394,7 +406,7 @@ Rails 6.1+ can serialize Class and Module objects as arguments to ActiveJob. The
|
|
394
406
|
deliver_by DeliveryMethods::Discord
|
395
407
|
```
|
396
408
|
|
397
|
-
For Rails 6.0
|
409
|
+
For Rails 6.0, you must pass strings of the class names in the `deliver_by` options.
|
398
410
|
|
399
411
|
```ruby
|
400
412
|
deliver_by :discord, class: "DeliveryMethods::Discord"
|
@@ -15,7 +15,7 @@ module Noticed
|
|
15
15
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
16
16
|
|
17
17
|
def generate_notification
|
18
|
-
generate :model, name, "recipient:references{polymorphic}", "type", params_column, "read_at:datetime", *attributes
|
18
|
+
generate :model, name, "recipient:references{polymorphic}", "type", params_column, "read_at:datetime:index", *attributes
|
19
19
|
end
|
20
20
|
|
21
21
|
def add_noticed_model
|
@@ -43,7 +43,7 @@ module Noticed
|
|
43
43
|
|
44
44
|
def params_column
|
45
45
|
case ActiveRecord::Base.configurations.configs_for(spec_name: "primary").config["adapter"]
|
46
|
-
when "
|
46
|
+
when "mysql2"
|
47
47
|
"params:json"
|
48
48
|
when "postgresql"
|
49
49
|
"params:jsonb"
|
data/lib/noticed/base.rb
CHANGED
@@ -17,18 +17,18 @@ module Noticed
|
|
17
17
|
|
18
18
|
def channel
|
19
19
|
@channel ||= begin
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
20
|
+
value = options[:channel]
|
21
|
+
case value
|
22
|
+
when String
|
23
|
+
value.constantize
|
24
|
+
when Symbol
|
25
|
+
notification.send(value)
|
26
|
+
when Class
|
27
|
+
value
|
28
|
+
else
|
29
|
+
Noticed::NotificationChannel
|
30
|
+
end
|
31
|
+
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -4,8 +4,31 @@ module Noticed
|
|
4
4
|
extend ActiveModel::Callbacks
|
5
5
|
define_model_callbacks :deliver
|
6
6
|
|
7
|
+
class_attribute :option_names, instance_writer: false, default: []
|
8
|
+
|
7
9
|
attr_reader :notification, :options, :params, :recipient, :record
|
8
10
|
|
11
|
+
class << self
|
12
|
+
# Copy option names from parent
|
13
|
+
def inherited(base) #:nodoc:
|
14
|
+
base.option_names = option_names.dup
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def options(*names)
|
19
|
+
option_names.concat Array.wrap(names)
|
20
|
+
end
|
21
|
+
alias_method :option, :options
|
22
|
+
|
23
|
+
def validate!(delivery_method_options)
|
24
|
+
option_names.each do |option_name|
|
25
|
+
unless delivery_method_options.key? option_name
|
26
|
+
raise ValidationError, "option `#{option_name}` must be set for #{name}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
9
32
|
def perform(args)
|
10
33
|
@notification = args[:notification_class].constantize.new(args[:params])
|
11
34
|
@options = args[:options]
|
@@ -26,11 +49,6 @@ module Noticed
|
|
26
49
|
raise NotImplementedError, "Delivery methods must implement a deliver method"
|
27
50
|
end
|
28
51
|
|
29
|
-
def self.validate!(options)
|
30
|
-
# Override this method in your custom DeliveryMethod class to validate the options
|
31
|
-
# and raise error, if invalid.
|
32
|
-
end
|
33
|
-
|
34
52
|
private
|
35
53
|
|
36
54
|
# Helper method for making POST requests from delivery methods
|
@@ -1,16 +1,12 @@
|
|
1
1
|
module Noticed
|
2
2
|
module DeliveryMethods
|
3
3
|
class Email < Base
|
4
|
+
option :mailer
|
5
|
+
|
4
6
|
def deliver
|
5
7
|
mailer.with(format).send(method.to_sym).deliver_later
|
6
8
|
end
|
7
9
|
|
8
|
-
def self.validate!(options)
|
9
|
-
unless options.key?(:mailer)
|
10
|
-
raise ValidationError, "email delivery method requires a 'mailer' to be specified"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
10
|
private
|
15
11
|
|
16
12
|
def mailer
|
data/lib/noticed/model.rb
CHANGED
@@ -32,10 +32,10 @@ module Noticed
|
|
32
32
|
# Rehydrate the database notification into the Notification object for rendering
|
33
33
|
def to_notification
|
34
34
|
@_notification ||= begin
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
instance = type.constantize.with(params)
|
36
|
+
instance.record = self
|
37
|
+
instance
|
38
|
+
end
|
39
39
|
end
|
40
40
|
|
41
41
|
def mark_as_read!
|
data/lib/noticed/translation.rb
CHANGED
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.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Oliver
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -119,7 +119,7 @@ homepage: https://github.com/excid3/noticed
|
|
119
119
|
licenses:
|
120
120
|
- MIT
|
121
121
|
metadata: {}
|
122
|
-
post_install_message:
|
122
|
+
post_install_message:
|
123
123
|
rdoc_options: []
|
124
124
|
require_paths:
|
125
125
|
- lib
|
@@ -134,8 +134,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
- !ruby/object:Gem::Version
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
|
-
rubygems_version: 3.1.
|
138
|
-
signing_key:
|
137
|
+
rubygems_version: 3.1.4
|
138
|
+
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: Notifications for Ruby on Rails applications
|
141
141
|
test_files: []
|