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: 0e7706d5483124adb87010ceb0c1dc612dbbef07e4cbb6f52eee2a0f817f99e9
4
- data.tar.gz: f8762e7bc2517a5f2720d2d9617a29d8720cc18fa1cad2129ba017c5e95ef012
3
+ metadata.gz: 2d0e31246689108b94262916f2128e1f1085dadb8b75cb62016a23d7c1a23236
4
+ data.tar.gz: 50caba92044342c95532737086eaebac4422f9a6fc370c84b75763d28f2360e4
5
5
  SHA512:
6
- metadata.gz: 277b1350289860ef9c2a33406fee80d8858ddf7dae84b62c0e960fe442e1645087d7c15ecd610e03e937faf8de8114c15a884f5b7807e276be0b7f58fcbff17b
7
- data.tar.gz: a93fb735486c3ed1abfc524798e260b2945844b72bbf2a671e8ef04b48de15ed52fca3756e79882359599040a69055871d97f29c15a07bab94617590c38d2b68
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 an initializer under `config/initializers/active_outbox.rb` and setup the default outbox class to the `Outbox` model you will create in the next step.
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:install
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 creating the initializer, create an `Outbox` table using the provided generator and corresponding model. Any model name can be passed as an argument but if empty it will default to just `outboxes`. The generated table name will be `model_name_outboxes`.
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:model <optional model_name>
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
- ### Multiple Outbox mappings
75
- If more granularity is desired multiple `Outbox` classes can be configured. After creating the needed `Outbox` classes for each module you can specify multiple mappings in the initializer.
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('Events', Module.new) unless module_parent.const_defined?('Events')
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, "#{const_name}#{namespace.blank? ? '' : '.'}#{namespace}")
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'] || Rails.root
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.blank? ? 'outboxes' : "#{model_name}_outboxes"
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class <%= path_name.camelize %> < ApplicationRecord
4
+ validates_presence_of :identifier, :payload, :aggregate, :aggregate_identifier, :event
5
+ end
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.1.3
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: 2023-11-10 00:00:00.000000000 Z
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.4.10
79
+ rubygems_version: 3.5.9
79
80
  signing_key:
80
81
  specification_version: 4
81
82
  summary: A Transactional Outbox implementation for ActiveRecord