active_outbox 0.0.5 → 0.1.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: 88b2644a74013b8c15f3ce2f4bb270cdb6603c19eba19221fe4cefa1bb0ac859
4
- data.tar.gz: 6ea80cb79adbe607ca93ca5710fce0a5b0fef1a22f24209811082b8ab7993261
3
+ metadata.gz: b2e8f16f629c433d2963d5e96dfc3e1b12031fafa5ea58ab4dc215a01a2f3517
4
+ data.tar.gz: 23d0bee29bb81d3bebf53f8e63efb1cb3356f365e6e662a2b0c1fb575843f347
5
5
  SHA512:
6
- metadata.gz: 6a5bce340343c741fd131938504c2040cdf130c6c8b0e989c2600744501e5ab57e248e373ddc6e16241d0d9967242d9885245b8a2a6252027a048bbede4175ae
7
- data.tar.gz: 3ae68085af021db07572b7d23b81c85b7e7a16f7c80e340e8fd3e1c68c3e0b37314ad1f4eefe37bc44bdf3b8b3f37329c31f83d76703896855ad211e8a0e2636
6
+ metadata.gz: 0ffb5a506f89addc09301f10401319de0aaccb6531a0a3532104fb62172a899cbbd36d08e56cf92297cacd999494b41f1ca22c0f6a4d579f7d3f29b47c2d1d5a
7
+ data.tar.gz: 0caa250db4098bbf5ad294da3fa487d75c5e6f58c0678933e4314ecc72f69e7600e747ed1149cdc89f892485a24da3381c0a9195242f1b4a9a61d8480271e8c7
data/README.md CHANGED
@@ -37,21 +37,13 @@ gem install active_outbox
37
37
 
38
38
  ## Usage
39
39
  ### Setup
40
- Create an `Outbox` table using the provided generator and corresponding model.
40
+ 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 `Outobx`. The generated table name will be `model_name_outboxes`.
41
41
  ```bash
42
- rails g active_outbox outbox
42
+ rails g active_outbox:model <optional model_name>
43
43
  ```
44
44
  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
- ```ruby
46
- # frozen_string_literal: true
47
-
48
- Rails.application.reloader.to_prepare do
49
- ActiveOutbox.configure do |config|
50
- config.outbox_mapping = {
51
- 'default' => 'Outbox'
52
- }
53
- end
54
- end
45
+ ```bash
46
+ rails g active_outbox:install
55
47
  ```
56
48
 
57
49
  To allow models to store Outbox records on changes, you will have to include the `Outboxable` concern.
@@ -3,15 +3,25 @@
3
3
  module ActiveOutbox
4
4
  module AdapterHelper
5
5
  def self.uuid_type
6
- postgres? ? 'uuid' : 'string'
6
+ return 'uuid' if postgres?
7
+ return 'string' if mysql?
8
+
9
+ 'string'
7
10
  end
8
11
 
9
12
  def self.json_type
10
- postgres? ? 'jsonb' : 'string'
13
+ return 'jsonb' if postgres?
14
+ return 'json' if mysql?
15
+
16
+ 'string'
11
17
  end
12
18
 
13
19
  def self.postgres?
14
20
  ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql'
15
21
  end
22
+
23
+ def self.mysql?
24
+ ActiveRecord::Base.connection.adapter_name.downcase == 'mysql2'
25
+ end
16
26
  end
17
27
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/concern'
4
+
3
5
  module ActiveOutbox
4
6
  module Outboxable
5
7
  extend ActiveSupport::Concern
data/lib/active_outbox.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'active_outbox/adapter_helper'
4
4
  require 'active_outbox/errors'
5
- require 'active_outbox/generators/active_outbox_generator'
6
5
  require 'active_outbox/outboxable'
7
6
  require 'active_outbox/railtie' if defined?(Rails::Railtie)
8
7
  require 'dry-configurable'
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/base'
4
+
5
+ module ActiveOutbox
6
+ module Generators
7
+ class InstallGenerator < Rails::Generators::Base
8
+ source_root File.expand_path('../templates', __dir__)
9
+
10
+ desc 'Creates an initializer file at config/initializers/active_outbox.rb'
11
+
12
+ def create_initializer_file
13
+ copy_file('initializer.rb', Rails.root.join('config', 'initializers', 'active_outbox.rb'))
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails'
4
+ require 'rails/generators/active_record'
5
+ require 'rails/generators/base'
6
+ require 'rails/generators/migration'
7
+
8
+ module ActiveOutbox
9
+ module Generators
10
+ class ModelGenerator < Rails::Generators::Base
11
+ source_root File.expand_path('../templates', __dir__)
12
+
13
+ include ActiveOutbox::AdapterHelper
14
+ include Rails::Generators::Migration
15
+
16
+ class << self
17
+ delegate :next_migration_number, to: ActiveRecord::Generators::Base
18
+ end
19
+
20
+ desc 'Creates the Outbox model migration'
21
+
22
+ argument :model_name, type: :string, default: ''
23
+ class_option :component_path, type: :string, desc: 'Indicates where to create the outbox migration'
24
+
25
+ def create_migration_file
26
+ migration_path = "#{root_path}/db/migrate"
27
+ migration_template(
28
+ 'migration.rb',
29
+ "#{migration_path}/active_outbox_create_#{table_name}.rb",
30
+ migration_version: migration_version
31
+ )
32
+ end
33
+
34
+ def root_path
35
+ options['component_path'] || Rails.root
36
+ end
37
+
38
+ def migration_version
39
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
40
+ end
41
+
42
+ def table_name
43
+ model_name.blank? ? 'outboxes' : "#{model_name}_outboxes"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.reloader.to_prepare do
4
+ ActiveOutbox.configure do |config|
5
+ # To configure which Outbox class maps to which domain
6
+ # See https://github.com/rootstrap/active_outbox#advanced-usage for advanced examples
7
+ config.outbox_mapping = {
8
+ 'default' => 'Outbox'
9
+ }
10
+
11
+ # Configure database adapter
12
+ # config.adapter = :postgresql
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ActiveOutboxCreate<%= table_name.camelize.singularize %> < ActiveRecord::Migration<%= migration_version %>
4
+ def change
5
+ create_table :<%= table_name %> do |t|
6
+ t.<%= ActiveOutbox::AdapterHelper.uuid_type %> :identifier, null: false, index: { unique: true }
7
+ t.string :event, null: false
8
+ t.<%= ActiveOutbox::AdapterHelper.json_type %> :payload
9
+ t.string :aggregate, null: false
10
+ t.<%= ActiveOutbox::AdapterHelper.uuid_type %> :aggregate_identifier, null: false, index: true
11
+
12
+ t.timestamps
13
+ end
14
+ end
15
+ 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.0.5
4
+ version: 0.1.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-10-24 00:00:00.000000000 Z
11
+ date: 2023-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -50,10 +50,12 @@ files:
50
50
  - lib/active_outbox.rb
51
51
  - lib/active_outbox/adapter_helper.rb
52
52
  - lib/active_outbox/errors.rb
53
- - lib/active_outbox/generators/active_outbox_generator.rb
54
- - lib/active_outbox/generators/templates/migration.rb
55
53
  - lib/active_outbox/outboxable.rb
56
54
  - lib/active_outbox/railtie.rb
55
+ - lib/generators/active_outbox/install/install_generator.rb
56
+ - lib/generators/active_outbox/model/model_generator.rb
57
+ - lib/generators/active_outbox/templates/initializer.rb
58
+ - lib/generators/active_outbox/templates/migration.rb
57
59
  homepage: https://rubygems.org/gems/active_outbox
58
60
  licenses:
59
61
  - MIT
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails'
4
- require 'rails/generators'
5
- require 'rails/generators/active_record'
6
-
7
- class ActiveOutboxGenerator < ActiveRecord::Generators::Base
8
- include ActiveOutbox::AdapterHelper
9
- source_root File.expand_path('templates', __dir__)
10
-
11
- class_option :root_components_path, type: :string, default: Rails.root
12
-
13
- def create_migration_files
14
- migration_path = "#{options['root_components_path']}/db/migrate"
15
- migration_template(
16
- 'migration.rb',
17
- "#{migration_path}/outbox_create_#{table_name}.rb",
18
- migration_version: migration_version
19
- )
20
- end
21
-
22
- def migration_version
23
- "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
24
- end
25
-
26
- def table_name
27
- "#{name}_outboxes"
28
- end
29
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class OutboxCreate<%= table_name.camelize.singularize %> < ActiveRecord::Migration<%= migration_version %>
4
- def change
5
- create_table :<%= table_name %> do |t|
6
- t.<%= uuid_type %> :identifier, null: false, index: { unique: true }
7
- t.string :event, null: false
8
- t.<%= json_type %> :payload
9
- t.string :aggregate, null: false
10
- t.<%= uuid_type %> :aggregate_identifier, null: false, index: true
11
-
12
- t.timestamps
13
- end
14
- end
15
- end