event_hub 1.0.0 → 1.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: f88590e890094b75995c444528f90a10ba26df7573927c6cbfd3a1db609a3c65
4
- data.tar.gz: 6b820bf00fe54147b2c4067f3bfb43a50d77b59f9c8e047939188fc761d6a646
3
+ metadata.gz: 2b8210587ddae3d73a60defbaaf3453da073c4dadb5f22b9da124fefc6b48dba
4
+ data.tar.gz: cba4f17fdab807b5d51f23e32e5f6bd8e3850b044b80586360bf13d8e946e9e0
5
5
  SHA512:
6
- metadata.gz: 906008f796563c57fe06c883ce24323aad1072110a11525ff35da682e4912f02ba336c737411c2999ccdd97b1ea11f58859f21fba478e342c1eab600c9c32b21
7
- data.tar.gz: 391b241d8c1957f8a4f27d9f12daf060a50fccf34a5630be4b711b62d60fabcc8c1f3323720d30082d811401a7644d35259d227bc1abb00ec9221b073a3c9c84
6
+ metadata.gz: 87fd3579dca7a99ac0fd4f3ead3086e757fb43ebbac8a9fbfa8aa2ef8f71ef9d093f4029ba30bf80cee478fd866084f871f2cf448aeb7a851ba737bef74b1033
7
+ data.tar.gz: 1a829b392c1683f83dbc0e8451afe14582803815eaa55f4b8f075100706c236dd95da347c70f7e68aa55bed45501ae316464056dc04aa09f6a8af62c9a18d5b4
data/Gemfile.lock CHANGED
@@ -1,15 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- event_hub (1.0.0)
4
+ event_hub (1.1.0)
5
+ activesupport (>= 5.0)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ activesupport (7.1.1)
11
+ base64
12
+ bigdecimal
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ connection_pool (>= 2.2.5)
15
+ drb
16
+ i18n (>= 1.6, < 2)
17
+ minitest (>= 5.1)
18
+ mutex_m
19
+ tzinfo (~> 2.0)
9
20
  ast (2.4.2)
21
+ base64 (0.1.1)
22
+ bigdecimal (3.1.4)
23
+ concurrent-ruby (1.2.2)
24
+ connection_pool (2.4.1)
10
25
  diff-lcs (1.5.0)
11
26
  docile (1.4.0)
27
+ drb (2.1.1)
28
+ ruby2_keywords
29
+ i18n (1.14.1)
30
+ concurrent-ruby (~> 1.0)
12
31
  json (2.6.3)
32
+ minitest (5.20.0)
33
+ mutex_m (0.1.2)
13
34
  parallel (1.23.0)
14
35
  parser (3.2.2.1)
15
36
  ast (~> 2.4.1)
@@ -53,16 +74,20 @@ GEM
53
74
  rubocop-capybara (~> 2.17)
54
75
  rubocop-factory_bot (~> 2.22)
55
76
  ruby-progressbar (1.13.0)
77
+ ruby2_keywords (0.0.5)
56
78
  simplecov (0.22.0)
57
79
  docile (~> 1.1)
58
80
  simplecov-html (~> 0.11)
59
81
  simplecov_json_formatter (~> 0.1)
60
82
  simplecov-html (0.12.3)
61
83
  simplecov_json_formatter (0.1.4)
84
+ tzinfo (2.0.6)
85
+ concurrent-ruby (~> 1.0)
62
86
  unicode-display_width (2.4.2)
63
87
 
64
88
  PLATFORMS
65
89
  x86_64-darwin-21
90
+ x86_64-darwin-22
66
91
  x86_64-linux
67
92
 
68
93
  DEPENDENCIES
data/README.md CHANGED
@@ -51,15 +51,23 @@ You need to implement the `event` and `event handler`:
51
51
  class Events::TickerUpserted < EventHub::Event
52
52
  event :user_registered
53
53
  version '1.1'
54
+ set_callback :publish, :after, :log
54
55
 
55
56
  attribute :id
56
57
  attribute :email
57
58
  attribute :name
59
+
60
+ private
61
+
62
+ def log
63
+ LogStasher.warn(event: :publish_event, event_name: self.class.event, attrs: as_json)
64
+ end
58
65
  end
59
66
 
60
67
  # app/event_hub/handlers/user_registered.rb
61
68
  class Handlers::UserRegistered < EventHub::Handler
62
69
  version '1.1'
70
+ set_callback :handle, :before, :log
63
71
 
64
72
  def call
65
73
  User.create(event.as_json)
@@ -77,6 +85,10 @@ class Handlers::UserRegistered < EventHub::Handler
77
85
  end
78
86
 
79
87
  private
88
+
89
+ def log
90
+ LogStasher.warn(event: :handle_event, event_name: @message.event, attrs: @message.attributes)
91
+ end
80
92
 
81
93
  def event
82
94
  @event ||= Events::UserRegistered.new(JSON.parse(message.body))
data/event_hub.gemspec CHANGED
@@ -31,6 +31,8 @@ Gem::Specification.new do |spec|
31
31
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ['lib']
33
33
 
34
+ spec.add_dependency 'activesupport', '>= 5.0'
35
+
34
36
  # For more information and examples about making a new gem, check out our
35
37
  # guide at: https://bundler.io/guides/creating_gem.html
36
38
  spec.metadata['rubygems_mfa_required'] = 'true'
@@ -4,6 +4,9 @@ require 'json'
4
4
 
5
5
  class EventHub
6
6
  class Event
7
+ include ::ActiveSupport::Callbacks
8
+ define_callbacks :publish
9
+
7
10
  def initialize(hash = {})
8
11
  hash.transform_keys(&:to_s).slice(*self.class.attributes.keys).each do |attr, val|
9
12
  public_send("#{attr}=", val)
@@ -11,7 +14,9 @@ class EventHub
11
14
  end
12
15
 
13
16
  def publish
14
- EventHub.publish(self)
17
+ run_callbacks :publish do
18
+ EventHub.publish(self)
19
+ end
15
20
  end
16
21
 
17
22
  def body
@@ -2,8 +2,19 @@
2
2
 
3
3
  class EventHub
4
4
  class Handler
5
+ include ::ActiveSupport::Callbacks
6
+ define_callbacks :handle
7
+
5
8
  attr_reader :message
6
9
 
10
+ def handle
11
+ run_callbacks :handle do
12
+ validate!
13
+ call
14
+ @message.ack
15
+ end
16
+ end
17
+
7
18
  def self.version(version = nil)
8
19
  @version = version if version
9
20
  @version
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class EventHub
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
data/lib/event_hub.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/callbacks'
3
4
  require_relative 'event_hub/version'
4
5
  require_relative 'event_hub/event'
5
6
  require_relative 'event_hub/handler'
@@ -31,10 +32,7 @@ class EventHub
31
32
  raise NoHandlerDefined unless handler_class
32
33
 
33
34
  handler = handler_class.new(message)
34
- handler.validate!
35
-
36
- handler.call
37
- message.ack
35
+ handler.handle
38
36
  rescue IgnoreMessage
39
37
  message.ack
40
38
  rescue RejectMessage
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_hub
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Guban
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-22 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2023-11-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
13
27
  description: This library structurizes the code for inter microservice communication
14
28
  using events
15
29
  email: