active_outbox 0.0.1 → 0.0.2

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: 114be65b9ebb769c48aebe0079432a121fb2f71b45ae912668eec8b0416a1761
4
- data.tar.gz: c0d9b1e730354d515c7ac9096369cce22774cc5b3ad5d9c77a0d5ace01d39e39
3
+ metadata.gz: aa92d48552facbc79e9ec9ae9f58a599d533267a490f7199c5b4e87b9f62f83b
4
+ data.tar.gz: a04f7dbe86d0b7e53296079be077db720c50baa48f2b53237cb18423fb33209d
5
5
  SHA512:
6
- metadata.gz: 94d42500e7272e0cefee12db79054308013edf4afdb6133a1f9a49f011e68596bbc005d4e2419d383dfb7f451558d1cd8bf63ae382a7a54d214c5847b0f6ff18
7
- data.tar.gz: e8b82acd7157417084c076f307da90a9138a6f424c0fae86f93190613dd47e409dde33407ab0397fc2b8464ccbfef67cb699147d52df7e1d263846dd143c2550
6
+ metadata.gz: acfbc64c4ad058a44d56c170fd194d300841cdfd8bdcaa950b9d63b90ae23f392f3bfdf7c1240e0564d7312680362057360114e9e98e9aaafec842639dd0ab98
7
+ data.tar.gz: 6449a7b730797fb16e55fca130e0ee7d4813bda5d06c34c4093f23bb6e20d77e5bca07cdcc5ed212d30c42617b6035ffcb31c2fc0033b90ebb0653dd6fe6bf25
@@ -1,9 +1,26 @@
1
1
  module ActiveOutbox
2
+ class << self
3
+ attr_accessor :configuration
4
+
5
+ def configuration
6
+ @configuration ||= ActiveOutbox::Configuration.new
7
+ end
8
+
9
+ def reset
10
+ @configuration = ActiveOutbox::Configuration.new
11
+ end
12
+
13
+ def configure
14
+ yield(configuration)
15
+ end
16
+ end
17
+
2
18
  class Configuration
3
- attr_accessor :adapter
19
+ attr_accessor :adapter, :outbox_mapping
4
20
 
5
21
  def initialize
6
- @adatper = :sqlite
22
+ @adapter = :sqlite
23
+ @outbox_mapping = {}
7
24
  end
8
25
  end
9
26
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveOutbox
4
+ class OutboxConfigurationError < StandardError; end
5
+ class OutboxClassNotFoundError < OutboxConfigurationError
6
+ def message
7
+ <<~MESSAGE
8
+ Missing Outbox class definition in module. Use `rails generate outbox <outbox model name>`.
9
+ Define default class in `config/initializers/active_outbox.rb`:
10
+
11
+ Rails.application.reloader.to_prepare do
12
+ ActiveOutbox.configure do |config|
13
+ config.outbox_mapping = {
14
+ 'Default' => <outbox model name>,
15
+ 'Meetings' => 'Meetings::Outbox'
16
+ }
17
+ end
18
+ end
19
+ MESSAGE
20
+ end
21
+ end
22
+ end
@@ -5,7 +5,6 @@ require 'rails/generators/active_record'
5
5
  class OutboxGenerator < ActiveRecord::Generators::Base
6
6
  source_root File.expand_path("../templates", __FILE__)
7
7
 
8
- argument :domains, type: :array, default: [], banner: "domain domain"
9
8
  class_option :root_components_path, type: :string, default: Rails.root
10
9
 
11
10
  def create_migration_files
@@ -4,8 +4,7 @@ module ActiveOutbox
4
4
  module Outboxable
5
5
  extend ActiveSupport::Concern
6
6
 
7
- included do |base|
8
- base.extend(ClassMethods)
7
+ included do
9
8
  *namespace, klass = name.underscore.upcase.split('/')
10
9
  namespace = namespace.reverse.join('.')
11
10
 
@@ -40,22 +39,21 @@ module ActiveOutbox
40
39
  super(**options, &block)
41
40
  end
42
41
 
43
- module ClassMethods
44
- def parent_module_name
45
- module_parent == Object ? '' : module_parent.name
46
- end
47
-
48
- def outbox_model
49
- @outbox_model ||= ActiveOutbox::Base.subclasses.find do |klass|
50
- klass.name.include?(parent_module_name)
51
- end
52
- end
53
- end
54
-
55
42
  private
56
43
 
57
44
  def create_outbox!(action, event_name)
58
- outbox = self.class.outbox_model.new(
45
+ unless self.class.module_parent.const_defined?('OUTBOX_MODEL')
46
+ *namespace, klass = self.class.name.underscore.upcase.split('/')
47
+ namespace = namespace.reverse.join('.')
48
+ outbox_model_name = ActiveOutbox.configuration.outbox_mapping[self.class.module_parent.name.underscore] ||
49
+ ActiveOutbox.configuration.outbox_mapping['default']
50
+ raise OutboxClassNotFoundError if outbox_model_name.nil?
51
+
52
+ outbox_model = outbox_model_name.safe_constantize
53
+ self.class.module_parent.const_set('OUTBOX_MODEL', outbox_model)
54
+ end
55
+
56
+ outbox = self.class.module_parent.const_get('OUTBOX_MODEL').new(
59
57
  aggregate: self.class.name,
60
58
  aggregate_identifier: try(:identifier) || id,
61
59
  event: @outbox_event || event_name,
@@ -0,0 +1,4 @@
1
+ module ActiveOutbox
2
+ class Railtie < Rails::Railtie
3
+ end
4
+ end
data/lib/active_outbox.rb CHANGED
@@ -1,26 +1,5 @@
1
- require 'active_outbox/base'
2
1
  require 'active_outbox/configuration'
2
+ require 'active_outbox/errors'
3
3
  require 'active_outbox/outboxable'
4
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
5
+ require 'active_outbox/railtie' if defined?(Rails::Railtie)
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.1
4
+ version: 0.0.2
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-06-28 00:00:00.000000000 Z
11
+ date: 2023-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -132,11 +132,12 @@ files:
132
132
  - README.md
133
133
  - bin/outbox
134
134
  - lib/active_outbox.rb
135
- - lib/active_outbox/base.rb
136
135
  - lib/active_outbox/configuration.rb
136
+ - lib/active_outbox/errors.rb
137
137
  - lib/active_outbox/generators/outbox_generator.rb
138
138
  - lib/active_outbox/generators/templates/migration.rb
139
139
  - lib/active_outbox/outboxable.rb
140
+ - lib/active_outbox/railtie.rb
140
141
  homepage: https://rubygems.org/gems/active_outbox
141
142
  licenses:
142
143
  - MIT
@@ -1,7 +0,0 @@
1
- require 'active_record'
2
-
3
- module ActiveOutbox
4
- class Base < ActiveRecord::Base
5
- self.abstract_class = true
6
- end
7
- end