nuntius 1.3.20 → 1.4.1

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: 4c35384ba46c7a00cccf82ae49b6ecf09e5e6c2439196ba5cd03d6d508a4ff1d
4
- data.tar.gz: bf0e4bde69a856f82f37c205d15f3685d4da3eb612cd2eaf582642bdd388574a
3
+ metadata.gz: be4761123ee4a2d8aaca7f70592b66c3f0f2c1a352596e10233f9e1f7fae1d82
4
+ data.tar.gz: 4a725d5bfa7f330ac1a7b89955b7df2aef3a56ee1ee36a8ea1a85074f26a6d77
5
5
  SHA512:
6
- metadata.gz: ddc8ce1306965ac2306ca8ab1d7e258478868d669b34b9eb997cb6dee6f747f0e06ac5149b51afb02dcdc3bb3f50eecefe0f3dfe035e771089ade69241537098
7
- data.tar.gz: f64fc4ad0d78a90f8c1cac8fb99106322af707387d10d0b51af82d1879a0ef77a3fb4f7c46414c4a9551f77cb473e1cb3e04d8f8b3d26ecf1342b2ad019f0e70
6
+ metadata.gz: 108cc9efe6c26d6cc223fe9c58f671bbfc95ac4992c1859feca5d9f4d718eab4811b60d045b04cec06595bfcdc77ecf18e391dce0de87a8cce6388c52cb98b94
7
+ data.tar.gz: afffc5c56327a134603c24520727ee9d1b76b527a1e378de6c350d71f459e488e8238c8dda9bf4ea562ce1b12107aa4d6bda3349109bafbc92f23815cb5abc8a
data/README.md CHANGED
@@ -64,6 +64,7 @@ class CarMessenger < Nuntius::BaseMessenger
64
64
  pdf = ApplicationController.renderer.new(http_host: object.account.hostname, https: true).render(template: "commercial_invoice/show", formats: [:pdf], assigns: {order: object})
65
65
 
66
66
  attachments << {content: StringIO.new(pdf), content_type: "application/pdf", filename: "commercial_invoice.pdf"}
67
+ # Return false here if you don't want the message to be sent
67
68
  end
68
69
  end
69
70
  ```
@@ -149,7 +150,7 @@ in a cronjob every 5 minutes with "bundle exec rails runner 'Nuntius::TimebasedE
149
150
  Beter even is using Sidekiq::Cron or GoodJob
150
151
 
151
152
  Nuntius will automatically prevent sending duplicates within the timerange you define.
152
- 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.
153
154
 
154
155
  ### Direct
155
156
 
@@ -5,13 +5,27 @@ module Nuntius
5
5
  class MessengerJob < ApplicationJob
6
6
  def perform(obj, event, params = {})
7
7
  return unless obj
8
+ ActiveRecord::Base.transaction do
9
+ messenger = Nuntius::BaseMessenger.messenger_for_obj(obj).new(obj, event, params)
10
+ return unless messenger.is_a?(Nuntius::CustomMessenger) || messenger.respond_to?(event.to_sym)
8
11
 
9
- messenger = Nuntius::BaseMessenger.messenger_for_obj(obj).new(obj, event, params)
10
- return unless messenger.is_a?(Nuntius::CustomMessenger) || messenger.respond_to?(event.to_sym)
12
+ result = messenger.call
13
+ return if result == false
11
14
 
12
- messenger.call
13
- templates = messenger.templates
14
- messenger.dispatch(templates) if templates.present?
15
+ templates = messenger.templates
16
+ messenger.dispatch(templates) if templates.present?
17
+ end
18
+ cleanup_nuntius_events(obj, event)
19
+ end
20
+
21
+ def cleanup_nuntius_events(obj, event)
22
+
23
+ nuntius_events = Nuntius::Event.where(
24
+ transitionable_id: obj["id"],
25
+ transitionable_type: obj["type"],
26
+ transition_event: event.to_s
27
+ )
28
+ nuntius_events.destroy_all
15
29
  end
16
30
  end
17
31
  end
@@ -22,9 +22,11 @@ module Nuntius
22
22
  # Calls the event method on the messenger
23
23
  def call
24
24
  select_templates
25
+ result = nil
25
26
  run_callbacks(:action) do
26
- send(@event.to_sym, @object, @params) if respond_to?(@event.to_sym)
27
+ result = send(@event.to_sym, @object, @params) if respond_to?(@event.to_sym)
27
28
  end
29
+ result
28
30
  end
29
31
 
30
32
  # Turns the templates in messages, and dispatches the messages to transports
@@ -0,0 +1,31 @@
1
+ module Nuntius
2
+ module Concerns
3
+ module EventsTransaction
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ state_machine do
8
+ after_transition any => any do |record, transition|
9
+ event = Nuntius::Event.find_or_initialize_by(
10
+ transitionable_id: record.id,
11
+ transitionable_type: record.class.to_s,
12
+ transition_event: transition.event.to_s,
13
+ transition_attribute: transition.attribute.to_s
14
+ )
15
+ event.update!(
16
+ transition_from: transition.from.to_s,
17
+ transition_to: transition.to.to_s
18
+ )
19
+ end
20
+ end
21
+
22
+ after_commit do
23
+ Nuntius::Event.all.each do |transition|
24
+ transitionable = transition.transitionable_type.constantize.find(transition.transitionable_id)
25
+ Nuntius.event(transition.transition_event.to_sym, transitionable)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,6 @@
1
+ module Nuntius
2
+ class Event < ApplicationRecord
3
+ belongs_to :transitionable, polymorphic: true
4
+ validates :transition_event, :transition_attribute, :transition_from, :transition_to, presence: true
5
+ end
6
+ end
@@ -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
@@ -18,6 +18,7 @@ module Nuntius::ActiveRecordHelpers
18
18
  @_nuntius_nuntiable_options = options
19
19
  include Nuntius::Nuntiable
20
20
  include Nuntius::StateMachine if options[:use_state_machine]
21
+ include Nuntius::Concerns::EventsTransaction if options[:use_state_machine]
21
22
  include Nuntius::Devise if options[:override_devise]
22
23
  include Nuntius::LifeCycle if options[:life_cycle]
23
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nuntius
4
- VERSION = "1.3.20"
4
+ VERSION = "1.4.1"
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.3.20
4
+ version: 1.4.1
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-03-28 00:00:00.000000000 Z
11
+ date: 2025-05-20 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: '1'
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: '1'
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,7 @@ 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
572
575
  - lib/generators/nuntius/install_generator.rb
573
576
  - lib/generators/nuntius/tailwind_config_generator.rb
574
577
  - lib/generators/nuntius/templates/config/initializers/nuntius.rb