noticed 1.2.17 → 1.2.19

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: 5dc2e5f50621a5b5da4f901c472621c2fce03d5f0f4db7c5a00a42de527e3128
4
- data.tar.gz: 1e07d7ea3599b7999d9a252a062ab38641cf6553c8392bf54d70ec9fbc164050
3
+ metadata.gz: 0e9bdeaab06d2b6aa2022dad0ed115e8a64e829d25276be05ffaec64d17116f3
4
+ data.tar.gz: ea1376e7faf08a81f2d691b0fec82f4a81647d3423f48260ac3d29b486f91a50
5
5
  SHA512:
6
- metadata.gz: 5f2dc0a1735bea8161241f7b384f722fd0a0d5bf1bac80424d63647d39cf9ef727839f3ba8320474c57da327e381daa46c533a788ca7d3ea1978c5eee10dcbfc
7
- data.tar.gz: 44eb3c5472b947d416d6f14bb2fa1b6a6d9ed26e853eb5d5ca559c0467c0dea9b83634fb1aac72a691b8fbd7805103e3029562e0800d0f433d2ecd9ab5a4e4d1
6
+ metadata.gz: 83514df616ee5334f50635cdf0be44a75919529dc2b35133175e49fc17f61fdf55f0a6d8401476262dbd9da4ae6f723361757df1cacea8f8091d10240459477f
7
+ data.tar.gz: 887876dd5b12f140829cb518ed9ccbff733bdd2d54486e16d7f088bb6fc1b3d6467d0efdd20336bd49fd044c7622b28b728ad7280e1c29e3ef508c23feff6124
data/README.md CHANGED
@@ -106,6 +106,7 @@ end
106
106
 
107
107
  * `if: :method_name` - Calls `method_name`and cancels delivery method if `false` is returned
108
108
  * `unless: :method_name` - Calls `method_name`and cancels delivery method if `true` is returned
109
+ * `delay: ActiveSupport::Duration` - Delays the delivery for the given duration of time
109
110
 
110
111
  ##### Helper Methods
111
112
 
@@ -186,7 +187,7 @@ Writes notification to the database.
186
187
 
187
188
  `deliver_by :database`
188
189
 
189
- **Note:** Database notifications are special in that they will run before the other delivery methods. We do this so you can reference the database record ID in other delivery methods.
190
+ **Note:** Database notifications are special in that they will run before the other delivery methods. We do this so you can reference the database record ID in other delivery methods. For that same reason, the delivery can't be delayed (via the `delay` option) or an error will be raised.
190
191
 
191
192
  ##### Options
192
193
 
@@ -521,7 +522,7 @@ class Post < ApplicationRecord
521
522
  end
522
523
  ```
523
524
 
524
- ##### Polymorphic Assocation
525
+ ##### Polymorphic Association
525
526
 
526
527
  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.
527
528
 
data/lib/noticed/base.rb CHANGED
@@ -85,9 +85,6 @@ module Noticed
85
85
 
86
86
  # Actually runs an individual delivery
87
87
  def run_delivery_method(delivery_method, recipient:, enqueue:)
88
- return if (delivery_method_name = delivery_method.dig(:options, :if)) && !send(delivery_method_name)
89
- return if (delivery_method_name = delivery_method.dig(:options, :unless)) && send(delivery_method_name)
90
-
91
88
  args = {
92
89
  notification_class: self.class.name,
93
90
  options: delivery_method[:options],
@@ -98,7 +95,15 @@ module Noticed
98
95
 
99
96
  run_callbacks delivery_method[:name] do
100
97
  method = delivery_method_for(delivery_method[:name], delivery_method[:options])
101
- enqueue ? method.perform_later(args) : method.perform_now(args)
98
+
99
+ # Always perfrom later if a delay is present
100
+ if (delay = delivery_method.dig(:options, :delay))
101
+ method.set(wait: delay).perform_later(args)
102
+ elsif enqueue
103
+ method.perform_later(args)
104
+ else
105
+ method.perform_now(args)
106
+ end
102
107
  end
103
108
  end
104
109
 
@@ -40,6 +40,9 @@ module Noticed
40
40
  @notification.record = args[:record]
41
41
  @notification.recipient = args[:recipient]
42
42
 
43
+ return if (condition = @options[:if]) && !@notification.send(condition)
44
+ return if (condition = @options[:unless]) && @notification.send(condition)
45
+
43
46
  run_callbacks :deliver do
44
47
  deliver
45
48
  end
@@ -6,6 +6,13 @@ module Noticed
6
6
  recipient.send(association_name).create!(attributes)
7
7
  end
8
8
 
9
+ def self.validate!(options)
10
+ super
11
+
12
+ # Must be executed right away so the other deliveries can access the db record
13
+ raise ArgumentError, "database delivery cannot be delayed" if options.key?(:delay)
14
+ end
15
+
9
16
  private
10
17
 
11
18
  def association_name
@@ -4,7 +4,7 @@ module Noticed
4
4
  option :mailer
5
5
 
6
6
  def deliver
7
- mailer.with(format).send(method.to_sym).deliver_later
7
+ mailer.with(format).send(method.to_sym).deliver_now
8
8
  end
9
9
 
10
10
  private
@@ -7,6 +7,8 @@ module Noticed
7
7
  if !options[:ignore_failure] && status != "0"
8
8
  raise ResponseUnsuccessful.new(response)
9
9
  end
10
+
11
+ response
10
12
  end
11
13
 
12
14
  private
@@ -1,3 +1,3 @@
1
1
  module Noticed
2
- VERSION = "1.2.17"
2
+ VERSION = "1.2.19"
3
3
  end
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.17
4
+ version: 1.2.19
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-10-27 00:00:00.000000000 Z
11
+ date: 2020-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: mocha
70
+ name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="