active_outbox 0.0.0 → 0.0.1

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: 2cd8cbc9b8aae5d2d62bdb50a0a9e8680f5eecee05009b26c9690853a71680a6
4
- data.tar.gz: a12cf4a81586d3a1cae47f38d1685d47cf7f96b655bd39b3abbdc9411448981f
3
+ metadata.gz: 114be65b9ebb769c48aebe0079432a121fb2f71b45ae912668eec8b0416a1761
4
+ data.tar.gz: c0d9b1e730354d515c7ac9096369cce22774cc5b3ad5d9c77a0d5ace01d39e39
5
5
  SHA512:
6
- metadata.gz: cbcbd18628600a8d67e7fae2fa4d6ecdff185d0c038bca08c21d84bc2532a82afefe512a18a61dd7bba868d02c2032b6ed65e045b069dbf5169764018a462ac7
7
- data.tar.gz: 4990897cf50199b4267ba8df57541570d3e644ea8c3c71f51898c4b19be16dacffff9c03596c0c4c12c706dc9ffeb15332934f8c273b6cf8efa60339e3a54f95
6
+ metadata.gz: 94d42500e7272e0cefee12db79054308013edf4afdb6133a1f9a49f011e68596bbc005d4e2419d383dfb7f451558d1cd8bf63ae382a7a54d214c5847b0f6ff18
7
+ data.tar.gz: e8b82acd7157417084c076f307da90a9138a6f424c0fae86f93190613dd47e409dde33407ab0397fc2b8464ccbfef67cb699147d52df7e1d263846dd143c2550
data/README.md CHANGED
@@ -1,2 +1,2 @@
1
- # active-outbox
1
+ # Active Outbox
2
2
  A Transactional Outbox implementation for ActiveRecord
data/bin/outbox ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rails'
4
+ require 'active_outbox'
5
+
6
+ rails g outbox ARGV[0]
@@ -1,3 +1,5 @@
1
+ require 'active_record'
2
+
1
3
  module ActiveOutbox
2
4
  class Base < ActiveRecord::Base
3
5
  self.abstract_class = true
@@ -0,0 +1,9 @@
1
+ module ActiveOutbox
2
+ class Configuration
3
+ attr_accessor :adapter
4
+
5
+ def initialize
6
+ @adatper = :sqlite
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ require 'rails'
2
+ require 'rails/generators'
1
3
  require 'rails/generators/active_record'
2
4
 
3
5
  class OutboxGenerator < ActiveRecord::Generators::Base
@@ -22,4 +24,16 @@ class OutboxGenerator < ActiveRecord::Generators::Base
22
24
  def table_name
23
25
  "#{name}_outboxes"
24
26
  end
27
+
28
+ def uuid_type
29
+ postgres? ? 'uuid' : 'string'
30
+ end
31
+
32
+ def json_type
33
+ postgres? ? 'jsonb' : 'string'
34
+ end
35
+
36
+ def postgres?
37
+ ActiveRecord::Base.connection.adapter_name.downcase == 'postgresql'
38
+ end
25
39
  end
@@ -1,11 +1,11 @@
1
1
  class OutboxCreate<%= table_name.camelize.singularize %> < ActiveRecord::Migration<%= migration_version %>
2
2
  def change
3
3
  create_table :<%= table_name %> do |t|
4
- t.uuid :identifier, null: false, index: { unique: true }
4
+ t.<%= uuid_type %> :identifier, null: false, index: { unique: true }
5
5
  t.string :event, null: false
6
- t.jsonb :payload
6
+ t.<%= json_type %> :payload
7
7
  t.string :aggregate, null: false
8
- t.uuid :aggregate_identifier, null: false, index: true
8
+ t.<%= uuid_type %> :aggregate_identifier, null: false, index: true
9
9
 
10
10
  t.timestamps
11
11
  end
@@ -60,7 +60,7 @@ module ActiveOutbox
60
60
  aggregate_identifier: try(:identifier) || id,
61
61
  event: @outbox_event || event_name,
62
62
  identifier: SecureRandom.uuid,
63
- payload: payload(action)
63
+ payload: formatted_payload(action)
64
64
  )
65
65
  @outbox_event = nil
66
66
 
@@ -73,6 +73,16 @@ module ActiveOutbox
73
73
  outbox.save!
74
74
  end
75
75
 
76
+ def formatted_payload(action)
77
+ payload = payload(action)
78
+ case ActiveRecord::Base.connection.adapter_name.downcase
79
+ when 'postgresql'
80
+ payload
81
+ else
82
+ payload.to_json
83
+ end
84
+ end
85
+
76
86
  def payload(action)
77
87
  payload = { before: nil, after: nil }
78
88
  case action
data/lib/active_outbox.rb CHANGED
@@ -1,2 +1,26 @@
1
1
  require 'active_outbox/base'
2
+ require 'active_outbox/configuration'
2
3
  require 'active_outbox/outboxable'
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
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_outbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillermo Aguirre
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-18 00:00:00.000000000 Z
11
+ date: 2023-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '7.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '7.0'
27
27
  - !ruby/object:Gem::Dependency
@@ -124,13 +124,16 @@ dependencies:
124
124
  version: 11.1.3
125
125
  description: A Transactional Outbox implementation for ActiveRecord
126
126
  email: guillermoaguirre1@gmail.com
127
- executables: []
127
+ executables:
128
+ - outbox
128
129
  extensions: []
129
130
  extra_rdoc_files: []
130
131
  files:
131
132
  - README.md
133
+ - bin/outbox
132
134
  - lib/active_outbox.rb
133
135
  - lib/active_outbox/base.rb
136
+ - lib/active_outbox/configuration.rb
134
137
  - lib/active_outbox/generators/outbox_generator.rb
135
138
  - lib/active_outbox/generators/templates/migration.rb
136
139
  - lib/active_outbox/outboxable.rb
@@ -138,7 +141,7 @@ homepage: https://rubygems.org/gems/active_outbox
138
141
  licenses:
139
142
  - MIT
140
143
  metadata: {}
141
- post_install_message:
144
+ post_install_message:
142
145
  rdoc_options: []
143
146
  require_paths:
144
147
  - lib
@@ -153,8 +156,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
156
  - !ruby/object:Gem::Version
154
157
  version: '0'
155
158
  requirements: []
156
- rubygems_version: 3.4.1
157
- signing_key:
159
+ rubygems_version: 3.1.6
160
+ signing_key:
158
161
  specification_version: 4
159
162
  summary: ActiveOutbox
160
163
  test_files: []