active_outbox 0.1.2 → 0.1.4

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: 0ef51af40668768f1f8b3acfcb1e81417f78bd676a1639beb6de68d0dd51b728
4
- data.tar.gz: 9e86368e8681ac70a24b4fce107bf786685f14ec1b0a8e89bd9e9a31eaae2117
3
+ metadata.gz: ef235321d10ec48e78a45e7b894ef50bffb6e73bf6e7d94971f19ed5f945e137
4
+ data.tar.gz: df6f204e1644416d5351af321e8f2cd832b0a7fad22e9d38385902f48e1e146b
5
5
  SHA512:
6
- metadata.gz: c79cd51c61496564df983885127498d97317df6ff891f6b524aca691fbb52d396a49f1d7226f25e8cb5f09b7261adc40dc817991ddbd4e8c852cfa43fab6ce69
7
- data.tar.gz: 047f6720232490e3cb89379012ff6204e7f89e53b888cd20d2c45228bcb6f0ab9e0a04d6885087d5daedda2856e22640948cd35785b7c64108580195f34e78c0
6
+ metadata.gz: f3322c31bd2dd05f239d5373fb772033583407576b5be4b14b184c5d97abc5ba1dd0aa7516e27b0f11519848d381948c8031c79c0d0916eaadd1566e78709d30
7
+ data.tar.gz: 803e2a29abded8d24ecd32492c39f19b26103769b47a7952d16114b5073bf5e42711d369e43f8d09e25cd9ce6d446c7492051e661d22f2c24becc66e25e7b66f
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
 
@@ -16,6 +16,12 @@ module ActiveOutbox
16
16
  'string'
17
17
  end
18
18
 
19
+ def self.bigint_type
20
+ return 'bigint' if postgres? || mysql?
21
+
22
+ 'integer'
23
+ end
24
+
19
25
  def self.postgres?
20
26
  ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql'
21
27
  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,11 +49,25 @@ 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
53
- options['uuid'].present? ? ActiveOutbox::AdapterHelper.uuid_type : 'integer'
70
+ options['uuid'].present? ? ActiveOutbox::AdapterHelper.uuid_type : ActiveOutbox::AdapterHelper.bigint_type
54
71
  end
55
72
  end
56
73
  end
@@ -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.2
4
+ version: 0.1.4
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: 2023-11-16 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