nuntius 1.1.4 → 1.2.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: 1dadbe5b3ded5dffcb6ceba8c5630fcce1d02905030087f3ac2fe7a5b0e94c0d
4
- data.tar.gz: 909fce72b52db1d9b24c2445a6e13767564f56f633fee205eeb0b8e497ed407f
3
+ metadata.gz: aa439d75f1be61c5122338f9d0c2c74b68d016e91208756d9ad2be119845ad51
4
+ data.tar.gz: 164ff8b68eb4912eaabade99a3ee39e593d5c2274345211601dccf14d6bb11c1
5
5
  SHA512:
6
- metadata.gz: 617adffb4414a45c2eb885666a030225b7338d736ead1960bce4aae499960c4123de259c48bdf04584e033b65809abf1e4cfe076e24c67961508c66ecdaea27b
7
- data.tar.gz: 1b8dba96defc70f262b455bbcd5ae87e5313e96e891910075eede92027c07811e524d1c25b83f0776b649b40e5bc1e11d0a771193069efa7f6bb52328f3d948d
6
+ metadata.gz: 3f40c494fc93610eee81a49f8b648b7cb3dafa8be578b051d24cfa8a052536ce69f6eb252df05eb98c5367bd28fe10c5109ad668b10efde3b015355282293e92
7
+ data.tar.gz: 65088baae2f8f957ac6dab1c14d9945d43e594149c9074d257d4a1db5f6f582a02801642c4348c3cd8b2a5c02c93ade63599d61d474869e30920a06e2d75cbd6
data/Rakefile CHANGED
@@ -33,7 +33,3 @@ Rake::TestTask.new(:test) do |t|
33
33
  end
34
34
 
35
35
  task default: :test
36
-
37
- # Adds the Auxilium semver task
38
- spec = Gem::Specification.find_by_name "auxilium"
39
- load "#{spec.gem_dir}/lib/tasks/semver.rake"
@@ -6,6 +6,7 @@ module Nuntius
6
6
 
7
7
  def deliver
8
8
  # NOTE: Attachments are not supported
9
+ # https://adaptivecards.io/designer/
9
10
  # https://learn.microsoft.com/en-us/power-automate/overview-adaptive-cards
10
11
  # https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=newteams%2Cdotnet
11
12
 
@@ -3,7 +3,8 @@
3
3
  require_relative "nuntiable"
4
4
  require_relative "devise"
5
5
  require_relative "state_machine"
6
- require_relative "transactio"
6
+ require_relative "life_cycle"
7
+ # require_relative "transactio"
7
8
 
8
9
  module Nuntius::ActiveRecordHelpers
9
10
  extend ActiveSupport::Concern
@@ -18,7 +19,7 @@ module Nuntius::ActiveRecordHelpers
18
19
  include Nuntius::Nuntiable
19
20
  include Nuntius::StateMachine if options[:use_state_machine]
20
21
  include Nuntius::Devise if options[:override_devise]
21
- include Nuntius::Transactio
22
+ include Nuntius::LifeCycle if options[:life_cycle]
22
23
  end
23
24
 
24
25
  def nuntiable?
@@ -7,12 +7,13 @@ module Nuntius
7
7
  included do
8
8
  raise "#{name} must be nuntiable" unless nuntiable?
9
9
 
10
- orchestrator = Evento::Orchestrator.new(self)
11
- orchestrator.define_event_methods_on(messenger, devise: true) { |object, options = {}| }
10
+ I18n.t('devise.mailer').keys.map(&:to_s).each do |event_name|
11
+ messenger.send(:define_method, event_name) { |object, options = {}| }
12
+ end
12
13
 
13
- orchestrator.override_devise_notification do |notification, *devise_params|
14
+ define_method(:send_devise_notification) do |notification, *devise_params|
14
15
  # All notifications have either a token as the first param, or nothing
15
- Nuntius.event(notification, self, {token: devise_params.first})
16
+ Nuntius.event(notification, self, { token: devise_params.first })
16
17
  end
17
18
  end
18
19
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "auxilium"
4
- require "evento"
5
4
  require "inky"
6
5
  require "faraday"
7
6
  require "faraday/follow_redirects"
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nuntius
4
+ module LifeCycle
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ raise "#{name} must be nuntiable" unless nuntiable?
9
+
10
+ after_commit do
11
+ if previously_persisted?
12
+ Nuntius.event(:destroy, self)
13
+ elsif previously_new_record?
14
+ Nuntius.event(:create, self)
15
+ Nuntius.event(:save, self)
16
+ else
17
+ Nuntius.event(:update, self)
18
+ Nuntius.event(:save, self)
19
+ end
20
+ end
21
+
22
+ %i[create destroy update save].each do |event_name|
23
+ next if messenger.method_defined?(event_name)
24
+ messenger.send(:define_method, event_name) { |object, options = {}| }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,18 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nuntius
4
+
4
5
  module StateMachine
5
6
  extend ActiveSupport::Concern
6
7
 
7
8
  included do
8
9
  raise "#{name} must be nuntiable" unless nuntiable?
9
10
 
10
- orchestrator = Evento::Orchestrator.new(self)
11
- orchestrator.define_event_methods_on(messenger, state_machine: true) { |object, options = {}| }
11
+ state_machine.events.map(&:name)
12
+ .reject { |event_name| messenger.method_defined?(event_name) }
13
+ .each do |event_name|
14
+ messenger.send(:define_method, event_name) { |object, options = {}| }
15
+ end
16
+
17
+ after_commit do
18
+ Thread.current['___nuntius_state_machine_events']&.each do |event|
19
+ Nuntius.event(event[:event], event[:object])
20
+ end
21
+ # After events are fired we can clear the events
22
+ Thread.current['___nuntius_state_machine_events'] = []
23
+ end
24
+
25
+ state_machine do
26
+ # This records events within the same thread, and clears them in the same thread.
27
+ # A different thread is a different transaction.
28
+ after_transition any => any do |record, transition|
29
+ ___record__nuntius_state_machine_event(transition.event, record)
30
+ ___record__nuntius_state_machine_event(:update, record)
31
+ ___record__nuntius_state_machine_event(:save, record)
32
+ end
12
33
 
13
- orchestrator.after_audit_trail_commit(:nuntius) do |resource_state_transition|
14
- resource = resource_state_transition.resource
15
- Nuntius.event(event, resource) if resource.nuntiable? && event.present?
34
+ def ___record__nuntius_state_machine_event(event, object)
35
+ Thread.current['___nuntius_state_machine_events'] ||= []
36
+ Thread.current['___nuntius_state_machine_events'] << { event: event, object: object }
37
+ end
16
38
  end
17
39
  end
18
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nuntius
4
- VERSION = "1.1.4"
4
+ VERSION = "1.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nuntius
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-21 00:00:00.000000000 Z
11
+ date: 2024-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: apnotic
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.56'
55
- - !ruby/object:Gem::Dependency
56
- name: evento
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: fcm
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -154,16 +140,16 @@ dependencies:
154
140
  name: labelary
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
- - - ">="
143
+ - - "~>"
158
144
  - !ruby/object:Gem::Version
159
- version: '0'
145
+ version: '0.5'
160
146
  type: :runtime
161
147
  prerelease: false
162
148
  version_requirements: !ruby/object:Gem::Requirement
163
149
  requirements:
164
- - - ">="
150
+ - - "~>"
165
151
  - !ruby/object:Gem::Version
166
- version: '0'
152
+ version: '0.5'
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: liquidum
169
155
  requirement: !ruby/object:Gem::Requirement
@@ -238,16 +224,16 @@ dependencies:
238
224
  name: parse-cron
239
225
  requirement: !ruby/object:Gem::Requirement
240
226
  requirements:
241
- - - ">="
227
+ - - "~>"
242
228
  - !ruby/object:Gem::Version
243
- version: '0'
229
+ version: '0.1'
244
230
  type: :runtime
245
231
  prerelease: false
246
232
  version_requirements: !ruby/object:Gem::Requirement
247
233
  requirements:
248
- - - ">="
234
+ - - "~>"
249
235
  - !ruby/object:Gem::Version
250
- version: '0'
236
+ version: '0.1'
251
237
  - !ruby/object:Gem::Dependency
252
238
  name: pg
253
239
  requirement: !ruby/object:Gem::Requirement
@@ -266,16 +252,16 @@ dependencies:
266
252
  name: premailer
267
253
  requirement: !ruby/object:Gem::Requirement
268
254
  requirements:
269
- - - ">="
255
+ - - "~>"
270
256
  - !ruby/object:Gem::Version
271
- version: '0'
257
+ version: '1.23'
272
258
  type: :runtime
273
259
  prerelease: false
274
260
  version_requirements: !ruby/object:Gem::Requirement
275
261
  requirements:
276
- - - ">="
262
+ - - "~>"
277
263
  - !ruby/object:Gem::Version
278
- version: '0'
264
+ version: '1.23'
279
265
  - !ruby/object:Gem::Dependency
280
266
  name: rails
281
267
  requirement: !ruby/object:Gem::Requirement
@@ -551,11 +537,11 @@ files:
551
537
  - lib/nuntius/devise.rb
552
538
  - lib/nuntius/engine.rb
553
539
  - lib/nuntius/i18n_store.rb
540
+ - lib/nuntius/life_cycle.rb
554
541
  - lib/nuntius/liquid/tags/attach_tag.rb
555
542
  - lib/nuntius/mail_allow_list.rb
556
543
  - lib/nuntius/nuntiable.rb
557
544
  - lib/nuntius/state_machine.rb
558
- - lib/nuntius/transactio.rb
559
545
  - lib/nuntius/version.rb
560
546
  - lib/preamble.rb
561
547
  - lib/tasks/nuntius_tasks.rake
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Nuntius
4
- module Transactio
5
- extend ActiveSupport::Concern
6
-
7
- included do
8
- raise "#{name} must be nuntiable" unless nuntiable?
9
-
10
- orchestrator = Evento::Orchestrator.new(self)
11
- if nuntiable_options[:life_cycle]
12
- orchestrator.define_event_methods_on(messenger, life_cycle: true) do |object, options = {}|
13
- end
14
- end
15
-
16
- orchestrator = Evento::Orchestrator.new(self)
17
- orchestrator.after_transaction_log_commit(:nuntius) do |transaction_log_entry|
18
- resource = transaction_log_entry.transaction_loggable
19
- event = transaction_log_entry.event
20
-
21
- if resource.present? && event.present? && resource.nuntiable?
22
- params = Nuntius.config.default_params(transaction_log_entry)
23
-
24
- Nuntius.event(event, resource, params)
25
- Nuntius.event("save", resource, params) if %w[create update].include?(event)
26
- end
27
- end
28
- end
29
- end
30
- end