nuntius 1.4.0 → 1.4.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 +4 -4
- data/README.md +1 -1
- data/app/jobs/nuntius/messenger_job.rb +17 -6
- data/app/models/nuntius/concerns/events_transaction.rb +43 -0
- data/app/models/nuntius/event.rb +6 -0
- data/app/models/nuntius/template.rb +4 -2
- data/db/migrate/20250520091916_create_nuntius_events_table.rb +12 -0
- data/db/migrate/20250521132554_update_nuntius_events_index.rb +9 -0
- data/lib/nuntius/active_record_helpers.rb +1 -2
- data/lib/nuntius/version.rb +1 -1
- data/lib/nuntius.rb +7 -4
- metadata +8 -5
- data/lib/nuntius/state_machine.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 503ba69f7497033d55a16b1ec419a8c7b9083c31e55ac8c80bfc93bbb3581f7c
|
4
|
+
data.tar.gz: c690591944454ff27e64faa46d0fad4240cc5f2124f5ee2c21182e991c268b20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33ebca7868482ad0f3682a719a160ce53c98ae232eb5416952cc676ad2c568a2eefa1c67073e87990ac99e0409315b9100c4be79b67434dd1dfeb2cda4fb2f94
|
7
|
+
data.tar.gz: 4b2aa8d8a6f238001c2f0610b3fd797d80b68860e1b1335453daf382988610d3f01a5760ec37ef5c287967ab0feb5140fe4772fc520dd67856dcbad3a9c5736f
|
data/README.md
CHANGED
@@ -150,7 +150,7 @@ in a cronjob every 5 minutes with "bundle exec rails runner 'Nuntius::TimebasedE
|
|
150
150
|
Beter even is using Sidekiq::Cron or GoodJob
|
151
151
|
|
152
152
|
Nuntius will automatically prevent sending duplicates within the timerange you define.
|
153
|
-
It will also ONLY send messages for objects (the one in template class), created after you created this template.
|
153
|
+
It will also ONLY send messages for objects (the one in template class), created after you created this template, this prevents sending dozens of emails which may make no sense, when you add a new template.
|
154
154
|
|
155
155
|
### Direct
|
156
156
|
|
@@ -3,17 +3,28 @@
|
|
3
3
|
# Initializes the appropriate Messenger class and calls the event method
|
4
4
|
module Nuntius
|
5
5
|
class MessengerJob < ApplicationJob
|
6
|
+
after_perform :cleanup_nuntius_events
|
7
|
+
|
6
8
|
def perform(obj, event, params = {})
|
7
9
|
return unless obj
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
ActiveRecord::Base.transaction do
|
12
|
+
messenger = Nuntius::BaseMessenger.messenger_for_obj(obj).new(obj, event, params)
|
13
|
+
return unless messenger.is_a?(Nuntius::CustomMessenger) || messenger.respond_to?(event.to_sym)
|
14
|
+
|
15
|
+
result = messenger.call
|
16
|
+
return if result == false
|
11
17
|
|
12
|
-
|
13
|
-
|
18
|
+
templates = messenger.templates
|
19
|
+
messenger.dispatch(templates) if templates.exists?
|
20
|
+
end
|
21
|
+
end
|
14
22
|
|
15
|
-
|
16
|
-
|
23
|
+
def cleanup_nuntius_events
|
24
|
+
Nuntius::Event.where(
|
25
|
+
transitionable: arguments.first,
|
26
|
+
transition_event: arguments.second.to_s
|
27
|
+
).delete_all
|
17
28
|
end
|
18
29
|
end
|
19
30
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Nuntius
|
2
|
+
module Concerns
|
3
|
+
module EventsTransaction
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
state_machine.events.map(&:name)
|
8
|
+
.reject { |event_name| messenger.method_defined?(event_name) }
|
9
|
+
.each do |event_name|
|
10
|
+
messenger.send(:define_method, event_name) { |object, options = {}| }
|
11
|
+
end
|
12
|
+
|
13
|
+
state_machine do
|
14
|
+
after_transition any => any do |object, transition|
|
15
|
+
if object.persisted? && Nuntius.templates?(object, transition.event)
|
16
|
+
Nuntius::Event.find_or_create_by!(
|
17
|
+
transitionable_type: object.class.name,
|
18
|
+
transitionable_id: object.id,
|
19
|
+
# transitionable: object,
|
20
|
+
transition_event: transition.event.to_s,
|
21
|
+
transition_attribute: transition.attribute.to_s
|
22
|
+
) do |event|
|
23
|
+
event.transition_from = transition.from.to_s
|
24
|
+
event.transition_to = transition.to.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
after_commit :dispatch_nuntius_events
|
31
|
+
end
|
32
|
+
|
33
|
+
def dispatch_nuntius_events
|
34
|
+
Nuntius::Event
|
35
|
+
.where(transitionable: self)
|
36
|
+
.includes(:transitionable)
|
37
|
+
.select(:transition_event, :transitionable_type, :transitionable_id).distinct.each do |event|
|
38
|
+
Nuntius.event(event.transition_event.to_sym, event.transitionable)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -33,8 +33,10 @@ module Nuntius
|
|
33
33
|
|
34
34
|
options = {registers: {"template" => self, "message" => message}}
|
35
35
|
|
36
|
-
message.to = render(:to, assigns, locale, options).split(
|
37
|
-
|
36
|
+
message.to = render(:to, assigns, locale, options).split(',').map(&:strip).reject{ |to| to == 'Liquid error internal' }.reject(&:empty?).join(',')
|
37
|
+
return unless message.to.present?
|
38
|
+
|
39
|
+
message.from = render(:from, assigns, locale, options).split(',').reject(&:empty?).join(',')
|
38
40
|
message.subject = render(:subject, assigns, locale, options)
|
39
41
|
message.html = render(:html, assigns, locale, options.merge(layout: layout&.data))
|
40
42
|
message.text = render(:text, assigns, locale, options)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateNuntiusEventsTable < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
create_table :nuntius_events do |t|
|
4
|
+
t.references :transitionable, type: :uuid, polymorphic: true
|
5
|
+
t.string :transition_attribute
|
6
|
+
t.string :transition_event
|
7
|
+
t.string :transition_from
|
8
|
+
t.string :transition_to
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class UpdateNuntiusEventsIndex < ActiveRecord::Migration[7.0]
|
2
|
+
def change
|
3
|
+
remove_index :nuntius_events, name: :index_nuntius_events_on_transitionable
|
4
|
+
|
5
|
+
add_index :nuntius_events,
|
6
|
+
[:transitionable_type, :transitionable_id, :transition_event],
|
7
|
+
name: :index_nuntius_events_on_type_id_event
|
8
|
+
end
|
9
|
+
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require_relative "nuntiable"
|
4
4
|
require_relative "devise"
|
5
|
-
require_relative "state_machine"
|
6
5
|
require_relative "life_cycle"
|
7
6
|
# require_relative "transactio"
|
8
7
|
|
@@ -17,7 +16,7 @@ module Nuntius::ActiveRecordHelpers
|
|
17
16
|
def nuntiable(options = {})
|
18
17
|
@_nuntius_nuntiable_options = options
|
19
18
|
include Nuntius::Nuntiable
|
20
|
-
include Nuntius::
|
19
|
+
include Nuntius::Concerns::EventsTransaction if options[:use_state_machine] || options[:state_machine]
|
21
20
|
include Nuntius::Devise if options[:override_devise]
|
22
21
|
include Nuntius::LifeCycle if options[:life_cycle]
|
23
22
|
end
|
data/lib/nuntius/version.rb
CHANGED
data/lib/nuntius.rb
CHANGED
@@ -50,10 +50,13 @@ module Nuntius
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def templates?(obj, event)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
messenger = Nuntius::BaseMessenger.messenger_for_obj(obj).new(obj, event)
|
54
|
+
return false unless messenger.is_a?(Nuntius::CustomMessenger) || messenger.respond_to?(event.to_sym)
|
55
|
+
|
56
|
+
result = messenger.call
|
57
|
+
return false if result == false
|
58
|
+
|
59
|
+
messenger.templates.exists?
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
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.4.
|
4
|
+
version: 1.4.3
|
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: 2025-
|
11
|
+
date: 2025-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apnotic
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: 1.2.1
|
160
160
|
type: :runtime
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
166
|
+
version: 1.2.1
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: mail
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -481,8 +481,10 @@ files:
|
|
481
481
|
- app/models/nuntius/application_record.rb
|
482
482
|
- app/models/nuntius/attachment.rb
|
483
483
|
- app/models/nuntius/campaign.rb
|
484
|
+
- app/models/nuntius/concerns/events_transaction.rb
|
484
485
|
- app/models/nuntius/concerns/metadata_scoped.rb
|
485
486
|
- app/models/nuntius/concerns/yamlify.rb
|
487
|
+
- app/models/nuntius/event.rb
|
486
488
|
- app/models/nuntius/inbound_message.rb
|
487
489
|
- app/models/nuntius/layout.rb
|
488
490
|
- app/models/nuntius/list.rb
|
@@ -569,6 +571,8 @@ files:
|
|
569
571
|
- db/migrate/20220412114148_add_last_sent_to_message.rb
|
570
572
|
- db/migrate/20240205204719_add_description_to_list.rb
|
571
573
|
- db/migrate/20240206203019_add_slug_to_nuntius_list.rb
|
574
|
+
- db/migrate/20250520091916_create_nuntius_events_table.rb
|
575
|
+
- db/migrate/20250521132554_update_nuntius_events_index.rb
|
572
576
|
- lib/generators/nuntius/install_generator.rb
|
573
577
|
- lib/generators/nuntius/tailwind_config_generator.rb
|
574
578
|
- lib/generators/nuntius/templates/config/initializers/nuntius.rb
|
@@ -584,7 +588,6 @@ files:
|
|
584
588
|
- lib/nuntius/liquid/tags/attach_tag.rb
|
585
589
|
- lib/nuntius/mail_allow_list.rb
|
586
590
|
- lib/nuntius/nuntiable.rb
|
587
|
-
- lib/nuntius/state_machine.rb
|
588
591
|
- lib/nuntius/version.rb
|
589
592
|
- lib/preamble.rb
|
590
593
|
- lib/tasks/nuntius_tasks.rake
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Nuntius
|
4
|
-
module StateMachine
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
raise "#{name} must be nuntiable" unless nuntiable?
|
9
|
-
|
10
|
-
state_machine.events.map(&:name)
|
11
|
-
.reject { |event_name| messenger.method_defined?(event_name) }
|
12
|
-
.each do |event_name|
|
13
|
-
messenger.send(:define_method, event_name) { |object, options = {}| }
|
14
|
-
end
|
15
|
-
|
16
|
-
after_commit do
|
17
|
-
Thread.current["___nuntius_state_machine_events"]&.each do |event|
|
18
|
-
Nuntius.event(event[:event], event[:object])
|
19
|
-
end
|
20
|
-
# After events are fired we can clear the events
|
21
|
-
Thread.current["___nuntius_state_machine_events"] = []
|
22
|
-
end
|
23
|
-
|
24
|
-
state_machine do
|
25
|
-
# This records events within the same thread, and clears them in the same thread.
|
26
|
-
# A different thread is a different transaction.
|
27
|
-
after_transition any => any do |record, transition|
|
28
|
-
___record__nuntius_state_machine_event(transition.event, record)
|
29
|
-
___record__nuntius_state_machine_event(:update, record)
|
30
|
-
___record__nuntius_state_machine_event(:save, record)
|
31
|
-
end
|
32
|
-
|
33
|
-
def ___record__nuntius_state_machine_event(event, object)
|
34
|
-
Thread.current["___nuntius_state_machine_events"] ||= []
|
35
|
-
Thread.current["___nuntius_state_machine_events"] << {event: event, object: object}
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|