active_outbox 0.1.3 → 0.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d0e31246689108b94262916f2128e1f1085dadb8b75cb62016a23d7c1a23236
|
4
|
+
data.tar.gz: 50caba92044342c95532737086eaebac4422f9a6fc370c84b75763d28f2360e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 906a6d7f317a8d178e20852601d3a52a89655e8bca6d72ebd0adb8dda5aca8d7385ab8fe8a9822380274b8e8c3c9a118e2fe14cf2f9e27c5cb926387b8dd0313
|
7
|
+
data.tar.gz: 3523ac574209865c4e061559a9517a434fb8fb43b37756abf512dc67d309bc6cedd6a870a98212de81325f2b0ab128456c42c0f4a05ee943d35c9d9213c60828
|
data/README.md
CHANGED
@@ -37,13 +37,16 @@ gem install active_outbox
|
|
37
37
|
|
38
38
|
## Usage
|
39
39
|
### Setup
|
40
|
-
Create
|
40
|
+
Create the outbox table and model using the provided generator. Any model name can be passed as an argument but if empty it will default to `outboxes` and `Outbox` respectively.
|
41
41
|
```bash
|
42
|
-
rails g active_outbox:
|
42
|
+
rails g active_outbox:model <optional model_name>
|
43
|
+
|
44
|
+
create db/migrate/20231115182800_active_outbox_create_<model_name_>outboxes.rb
|
45
|
+
create app/models/<model_name_>outbox.rb
|
43
46
|
```
|
44
|
-
After
|
47
|
+
After running the migration, create an initializer under `config/initializers/active_outbox.rb` and setup the default outbox class to the new `Outbox` model you just created.
|
45
48
|
```bash
|
46
|
-
rails g active_outbox:
|
49
|
+
rails g active_outbox:install
|
47
50
|
```
|
48
51
|
|
49
52
|
To allow models to store Outbox records on changes, you will have to include the `Outboxable` concern.
|
@@ -71,8 +74,15 @@ By default our Outbox migration has an `aggregate_identifier` field which serves
|
|
71
74
|
```bash
|
72
75
|
rails g active_outbox:model <optional model_name> --uuid
|
73
76
|
```
|
74
|
-
###
|
75
|
-
If more granularity is desired multiple
|
77
|
+
### Modularized Outbox Mappings
|
78
|
+
If more granularity is desired multiple outbox classes can be configured. Using the provided generators we can specify namespaces and the folder structure.
|
79
|
+
```bash
|
80
|
+
rails g active_outbox:model user_access/ --component-path packs/user_access
|
81
|
+
|
82
|
+
create packs/user_access/db/migrate/20231115181205_active_outbox_create_user_access_outboxes.rb
|
83
|
+
create packs/user_access/app/models/user_access/outbox.rb
|
84
|
+
```
|
85
|
+
After creating the needed `Outbox` classes for each module you can specify multiple mappings in the initializer.
|
76
86
|
```ruby
|
77
87
|
# frozen_string_literal: true
|
78
88
|
|
@@ -10,16 +10,21 @@ module ActiveOutbox
|
|
10
10
|
*namespace, klass = name.underscore.upcase.split('/')
|
11
11
|
namespace = namespace.reverse.join('.')
|
12
12
|
|
13
|
-
module_parent.const_set('
|
13
|
+
module_parent.const_set('ActiveOutbox', Module.new) unless module_parent.const_defined?('ActiveOutbox', false)
|
14
|
+
|
15
|
+
unless module_parent::ActiveOutbox.const_defined?('Events', false)
|
16
|
+
module_parent::ActiveOutbox.const_set('Events', Module.new)
|
17
|
+
end
|
14
18
|
|
15
19
|
{ create: 'CREATED', update: 'UPDATED', destroy: 'DESTROYED' }.each do |key, value|
|
16
20
|
const_name = "#{klass}_#{value}"
|
17
21
|
|
18
|
-
unless module_parent::Events.const_defined?(const_name)
|
19
|
-
module_parent::Events.const_set(const_name,
|
22
|
+
unless module_parent::ActiveOutbox::Events.const_defined?(const_name)
|
23
|
+
module_parent::ActiveOutbox::Events.const_set(const_name,
|
24
|
+
"#{const_name}#{namespace.blank? ? '' : '.'}#{namespace}")
|
20
25
|
end
|
21
26
|
|
22
|
-
event_name = module_parent::Events.const_get(const_name)
|
27
|
+
event_name = module_parent::ActiveOutbox::Events.const_get(const_name)
|
23
28
|
|
24
29
|
send("after_#{key}") { create_outbox!(key, event_name) }
|
25
30
|
end
|
@@ -35,10 +35,13 @@ module ActiveOutbox
|
|
35
35
|
"#{migration_path}/active_outbox_create_#{table_name}.rb",
|
36
36
|
migration_version: migration_version
|
37
37
|
)
|
38
|
+
|
39
|
+
template('model.rb', "#{root_path}/app/models/#{path_name}.rb")
|
38
40
|
end
|
39
41
|
|
40
42
|
def root_path
|
41
|
-
options['component_path']
|
43
|
+
path = options['component_path'].blank? ? '' : "/#{options['component_path']}"
|
44
|
+
"#{Rails.root}#{path}"
|
42
45
|
end
|
43
46
|
|
44
47
|
def migration_version
|
@@ -46,7 +49,21 @@ module ActiveOutbox
|
|
46
49
|
end
|
47
50
|
|
48
51
|
def table_name
|
49
|
-
model_name.
|
52
|
+
*namespace, name = model_name.downcase.split('/')
|
53
|
+
name = name.blank? ? 'outboxes' : "#{name}_outboxes"
|
54
|
+
namespace = namespace.join('_')
|
55
|
+
namespace.blank? ? name : "#{namespace}_#{name}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def path_name
|
59
|
+
name = ''
|
60
|
+
*namespace = model_name.downcase.split('/')
|
61
|
+
if (model_name.include?('/') && model_name.last != '/' && namespace.length > 1) || !model_name.include?('/')
|
62
|
+
name = namespace.pop
|
63
|
+
end
|
64
|
+
name = name.blank? ? 'outbox' : "#{name}_outbox"
|
65
|
+
namespace = namespace.join('/')
|
66
|
+
namespace.blank? ? name : "#{namespace}/#{name}"
|
50
67
|
end
|
51
68
|
|
52
69
|
def aggregate_identifier_type
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillermo Aguirre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-configurable
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/generators/active_outbox/model/model_generator.rb
|
57
57
|
- lib/generators/active_outbox/templates/initializer.rb
|
58
58
|
- lib/generators/active_outbox/templates/migration.rb
|
59
|
+
- lib/generators/active_outbox/templates/model.rb
|
59
60
|
homepage: https://rubygems.org/gems/active_outbox
|
60
61
|
licenses:
|
61
62
|
- MIT
|
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
76
|
- !ruby/object:Gem::Version
|
76
77
|
version: '0'
|
77
78
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
79
|
+
rubygems_version: 3.5.9
|
79
80
|
signing_key:
|
80
81
|
specification_version: 4
|
81
82
|
summary: A Transactional Outbox implementation for ActiveRecord
|