active_outbox 0.0.1 → 0.0.2
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/lib/active_outbox/configuration.rb +19 -2
- data/lib/active_outbox/errors.rb +22 -0
- data/lib/active_outbox/generators/outbox_generator.rb +0 -1
- data/lib/active_outbox/outboxable.rb +13 -15
- data/lib/active_outbox/railtie.rb +4 -0
- data/lib/active_outbox.rb +2 -23
- metadata +4 -3
- data/lib/active_outbox/base.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa92d48552facbc79e9ec9ae9f58a599d533267a490f7199c5b4e87b9f62f83b
|
4
|
+
data.tar.gz: a04f7dbe86d0b7e53296079be077db720c50baa48f2b53237cb18423fb33209d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acfbc64c4ad058a44d56c170fd194d300841cdfd8bdcaa950b9d63b90ae23f392f3bfdf7c1240e0564d7312680362057360114e9e98e9aaafec842639dd0ab98
|
7
|
+
data.tar.gz: 6449a7b730797fb16e55fca130e0ee7d4813bda5d06c34c4093f23bb6e20d77e5bca07cdcc5ed212d30c42617b6035ffcb31c2fc0033b90ebb0653dd6fe6bf25
|
@@ -1,9 +1,26 @@
|
|
1
1
|
module ActiveOutbox
|
2
|
+
class << self
|
3
|
+
attr_accessor :configuration
|
4
|
+
|
5
|
+
def configuration
|
6
|
+
@configuration ||= ActiveOutbox::Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def reset
|
10
|
+
@configuration = ActiveOutbox::Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
yield(configuration)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
2
18
|
class Configuration
|
3
|
-
attr_accessor :adapter
|
19
|
+
attr_accessor :adapter, :outbox_mapping
|
4
20
|
|
5
21
|
def initialize
|
6
|
-
@
|
22
|
+
@adapter = :sqlite
|
23
|
+
@outbox_mapping = {}
|
7
24
|
end
|
8
25
|
end
|
9
26
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveOutbox
|
4
|
+
class OutboxConfigurationError < StandardError; end
|
5
|
+
class OutboxClassNotFoundError < OutboxConfigurationError
|
6
|
+
def message
|
7
|
+
<<~MESSAGE
|
8
|
+
Missing Outbox class definition in module. Use `rails generate outbox <outbox model name>`.
|
9
|
+
Define default class in `config/initializers/active_outbox.rb`:
|
10
|
+
|
11
|
+
Rails.application.reloader.to_prepare do
|
12
|
+
ActiveOutbox.configure do |config|
|
13
|
+
config.outbox_mapping = {
|
14
|
+
'Default' => <outbox model name>,
|
15
|
+
'Meetings' => 'Meetings::Outbox'
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
MESSAGE
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -5,7 +5,6 @@ require 'rails/generators/active_record'
|
|
5
5
|
class OutboxGenerator < ActiveRecord::Generators::Base
|
6
6
|
source_root File.expand_path("../templates", __FILE__)
|
7
7
|
|
8
|
-
argument :domains, type: :array, default: [], banner: "domain domain"
|
9
8
|
class_option :root_components_path, type: :string, default: Rails.root
|
10
9
|
|
11
10
|
def create_migration_files
|
@@ -4,8 +4,7 @@ module ActiveOutbox
|
|
4
4
|
module Outboxable
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
-
included do
|
8
|
-
base.extend(ClassMethods)
|
7
|
+
included do
|
9
8
|
*namespace, klass = name.underscore.upcase.split('/')
|
10
9
|
namespace = namespace.reverse.join('.')
|
11
10
|
|
@@ -40,22 +39,21 @@ module ActiveOutbox
|
|
40
39
|
super(**options, &block)
|
41
40
|
end
|
42
41
|
|
43
|
-
module ClassMethods
|
44
|
-
def parent_module_name
|
45
|
-
module_parent == Object ? '' : module_parent.name
|
46
|
-
end
|
47
|
-
|
48
|
-
def outbox_model
|
49
|
-
@outbox_model ||= ActiveOutbox::Base.subclasses.find do |klass|
|
50
|
-
klass.name.include?(parent_module_name)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
42
|
private
|
56
43
|
|
57
44
|
def create_outbox!(action, event_name)
|
58
|
-
|
45
|
+
unless self.class.module_parent.const_defined?('OUTBOX_MODEL')
|
46
|
+
*namespace, klass = self.class.name.underscore.upcase.split('/')
|
47
|
+
namespace = namespace.reverse.join('.')
|
48
|
+
outbox_model_name = ActiveOutbox.configuration.outbox_mapping[self.class.module_parent.name.underscore] ||
|
49
|
+
ActiveOutbox.configuration.outbox_mapping['default']
|
50
|
+
raise OutboxClassNotFoundError if outbox_model_name.nil?
|
51
|
+
|
52
|
+
outbox_model = outbox_model_name.safe_constantize
|
53
|
+
self.class.module_parent.const_set('OUTBOX_MODEL', outbox_model)
|
54
|
+
end
|
55
|
+
|
56
|
+
outbox = self.class.module_parent.const_get('OUTBOX_MODEL').new(
|
59
57
|
aggregate: self.class.name,
|
60
58
|
aggregate_identifier: try(:identifier) || id,
|
61
59
|
event: @outbox_event || event_name,
|
data/lib/active_outbox.rb
CHANGED
@@ -1,26 +1,5 @@
|
|
1
|
-
require 'active_outbox/base'
|
2
1
|
require 'active_outbox/configuration'
|
2
|
+
require 'active_outbox/errors'
|
3
3
|
require 'active_outbox/outboxable'
|
4
4
|
require 'active_outbox/generators/outbox_generator'
|
5
|
-
|
6
|
-
module ActiveOutbox
|
7
|
-
class << self
|
8
|
-
attr_accessor :configuration
|
9
|
-
|
10
|
-
def configuration
|
11
|
-
@configuration ||= Configuration.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def reset
|
15
|
-
@configuration = Configuration.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def configure
|
19
|
-
yield(configuration)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def configuration
|
24
|
-
@configuration ||= Configuration.new
|
25
|
-
end
|
26
|
-
end
|
5
|
+
require 'active_outbox/railtie' if defined?(Rails::Railtie)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_outbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillermo Aguirre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -132,11 +132,12 @@ files:
|
|
132
132
|
- README.md
|
133
133
|
- bin/outbox
|
134
134
|
- lib/active_outbox.rb
|
135
|
-
- lib/active_outbox/base.rb
|
136
135
|
- lib/active_outbox/configuration.rb
|
136
|
+
- lib/active_outbox/errors.rb
|
137
137
|
- lib/active_outbox/generators/outbox_generator.rb
|
138
138
|
- lib/active_outbox/generators/templates/migration.rb
|
139
139
|
- lib/active_outbox/outboxable.rb
|
140
|
+
- lib/active_outbox/railtie.rb
|
140
141
|
homepage: https://rubygems.org/gems/active_outbox
|
141
142
|
licenses:
|
142
143
|
- MIT
|