messaging 3.5.1 → 3.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/messaging.rb +11 -0
- data/lib/messaging/adapters.rb +2 -0
- data/lib/messaging/message.rb +28 -2
- data/lib/messaging/rails/railtie.rb +4 -0
- data/lib/messaging/routes.rb +12 -1
- data/lib/messaging/routing.rb +28 -2
- data/lib/messaging/routing/enqueued_route.rb +1 -1
- data/lib/messaging/routing/route.rb +3 -3
- data/lib/messaging/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9af5bcee24c4ab1eebcfb97e77a4793431b149e9a00ffd7cfe8d6dfb3985aa02
|
4
|
+
data.tar.gz: bc2f7fc37a5b759691c9ea31398304ca0515a5d6e7ee0db7a3eccf4c79e3c534
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 278f0251732828f67528b8ce72e7455df587ce18b8a1e68a26f25a43d33516b36f4b0a3e008e3fc785a7f97d73b58946a89b946ff0f34edc8c3c6b5189fe27d4
|
7
|
+
data.tar.gz: 5cc743e11eac703f43783db84a2db14e88ddd6cf5a4e4f4d124589894c37edd3f1eb9ab2e07dcd7bb428a5dc0f4aa343f0037c0905cd83a4987f800b7c8be333
|
data/Gemfile.lock
CHANGED
data/lib/messaging.rb
CHANGED
@@ -56,6 +56,17 @@ module Messaging
|
|
56
56
|
routes.inline!(&block)
|
57
57
|
end
|
58
58
|
|
59
|
+
def self.without_dispatch(&block)
|
60
|
+
current_dispatcher = Config.dispatcher.adapter
|
61
|
+
Config.dispatcher.adapter = :null_adapter
|
62
|
+
|
63
|
+
result = block.call
|
64
|
+
|
65
|
+
ensure
|
66
|
+
Config.dispatcher.adapter = current_dispatcher
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
59
70
|
def self.category(name)
|
60
71
|
message_store.category(name)
|
61
72
|
end
|
data/lib/messaging/adapters.rb
CHANGED
data/lib/messaging/message.rb
CHANGED
@@ -25,6 +25,32 @@ module Messaging
|
|
25
25
|
end
|
26
26
|
|
27
27
|
module ClassMethods
|
28
|
+
# The stream that the message will be stored in when published.
|
29
|
+
#
|
30
|
+
# Stream names consists of the stream category and the stream id separated by a $.
|
31
|
+
# For instance "customer$123" where "customer" is the category and "123" is the id.
|
32
|
+
#
|
33
|
+
# When no stream name is given the message will not be persisted in the message store.
|
34
|
+
#
|
35
|
+
# @param [#call,String,nil] name The name of the stream, will be evaluated in the context
|
36
|
+
# of the message instance.
|
37
|
+
#
|
38
|
+
# @example
|
39
|
+
# class CustomerRegistered
|
40
|
+
# include Messaging::Message
|
41
|
+
#
|
42
|
+
# stream_name -> { "customer$#{customer_id}"}
|
43
|
+
#
|
44
|
+
# attribute :customer_id, Integer
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# CustomerRegistered.new(customer_id: 123).stream_name
|
48
|
+
# # => "customer$123"
|
49
|
+
def stream_name(name = nil)
|
50
|
+
return @stream_name unless name
|
51
|
+
@stream_name = name
|
52
|
+
end
|
53
|
+
|
28
54
|
# By default the topic is the same as the name of the message.
|
29
55
|
# We change the / that would be set for a namespaced message as "/" isn't valid in a topic
|
30
56
|
# To change the topic for a message just set it to whatever you want in your class definition.
|
@@ -88,8 +114,8 @@ module Messaging
|
|
88
114
|
end
|
89
115
|
|
90
116
|
def stream_name
|
91
|
-
|
92
|
-
|
117
|
+
return unless self.class.stream_name
|
118
|
+
instance_exec(&self.class.stream_name)
|
93
119
|
end
|
94
120
|
|
95
121
|
def stream_category
|
data/lib/messaging/routes.rb
CHANGED
@@ -51,7 +51,18 @@ module Messaging
|
|
51
51
|
|
52
52
|
# Public: Evaluate route definition.
|
53
53
|
def draw(&block)
|
54
|
-
|
54
|
+
routing_definition_blocks << block
|
55
|
+
end
|
56
|
+
|
57
|
+
def routing_definition_blocks
|
58
|
+
@routing_definition_blocks ||= []
|
59
|
+
end
|
60
|
+
|
61
|
+
def finalize_routes
|
62
|
+
clear_routes!
|
63
|
+
routing_definition_blocks.each do |block|
|
64
|
+
instance_eval(&block)
|
65
|
+
end
|
55
66
|
end
|
56
67
|
|
57
68
|
private
|
data/lib/messaging/routing.rb
CHANGED
@@ -5,6 +5,32 @@ require 'messaging/routing/enqueue_message_handler'
|
|
5
5
|
|
6
6
|
module Messaging
|
7
7
|
module Routing
|
8
|
+
def self.included(base)
|
9
|
+
base.send :extend, ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def definitions
|
14
|
+
@definitions ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
def on(pattern, **options, &block)
|
18
|
+
definitions << { pattern: pattern, options: options, block: block }
|
19
|
+
end
|
20
|
+
|
21
|
+
def new(*args, &block)
|
22
|
+
instance = allocate
|
23
|
+
|
24
|
+
# Pre-initialize
|
25
|
+
definitions.each do |definition|
|
26
|
+
instance.on(definition[:pattern], definition[:options], &definition[:block])
|
27
|
+
end
|
28
|
+
|
29
|
+
instance.send(:initialize, *args, &block)
|
30
|
+
instance
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
8
34
|
# Public: Sets up routes for the events that matches the given pattern
|
9
35
|
#
|
10
36
|
# pattern - Which messages to route. Can be a string, a regexp,
|
@@ -44,8 +70,8 @@ module Messaging
|
|
44
70
|
end
|
45
71
|
|
46
72
|
# Internal: Handles the message with the matching subscribers
|
47
|
-
def handle(message)
|
48
|
-
routes.map { |route| route.call(message) }
|
73
|
+
def handle(message, context = self)
|
74
|
+
routes.map { |route| route.call(message, context) }
|
49
75
|
message
|
50
76
|
end
|
51
77
|
|
@@ -11,14 +11,14 @@ module Messaging
|
|
11
11
|
|
12
12
|
def initialize(pattern, handler)
|
13
13
|
@matcher = MessageMatcher.new(pattern: pattern)
|
14
|
-
@handler = handler
|
14
|
+
@handler = handler.respond_to?(:to_proc) ? handler : handler.method(:call)
|
15
15
|
verify_handler!
|
16
16
|
end
|
17
17
|
|
18
|
-
def call(message)
|
18
|
+
def call(message, context = self)
|
19
19
|
return unless @matcher.matches?(message)
|
20
20
|
|
21
|
-
|
21
|
+
context.instance_exec(message, &@handler)
|
22
22
|
end
|
23
23
|
|
24
24
|
def topics
|
data/lib/messaging/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: messaging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.5.
|
4
|
+
version: 3.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bukowskis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -351,7 +351,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
351
351
|
- !ruby/object:Gem::Version
|
352
352
|
version: '0'
|
353
353
|
requirements: []
|
354
|
-
rubygems_version: 3.
|
354
|
+
rubygems_version: 3.1.4
|
355
355
|
signing_key:
|
356
356
|
specification_version: 4
|
357
357
|
summary: A library for decoupling applications by using messaging to communicate between
|