tiny_bus 1.0.1 → 1.0.2
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/lib/tiny_bus.rb +9 -5
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb6142b34ec3c5c72a2a4073b080d8aba77dd40b9c04df3df89d9802a26c5c39
|
4
|
+
data.tar.gz: b94962edf28bd4ad4affecb69cfd6d68d298b6623b98518cbbc9059fc117c83d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a29c06a16aab93b03d5a68384c55a4f461dd2a5e3b06c888d0d420325cd169dd1a16284af10a467eeb6953a525a809287deed3b25781a831ade89847d8dd0aa
|
7
|
+
data.tar.gz: 05de4ca2e32edad9a3d63a065752c1990135d5de66710f957dfbc49838a6f45e2ffb9b4c901f831a073bbf14dd4a5291ef62c9d96a9219a9021c4a32f197176b
|
data/lib/tiny_bus.rb
CHANGED
@@ -48,7 +48,7 @@ class TinyBus
|
|
48
48
|
# reserved for internal TinyBus usage, such as:
|
49
49
|
# - .log
|
50
50
|
def sub(topic, subber)
|
51
|
-
raise TinyBus::SubscriptionToDotTopicError.new("Cannot subscribe to dot topic `#{topic}', because
|
51
|
+
raise TinyBus::SubscriptionToDotTopicError.new("Cannot subscribe to dot topic `#{topic}', because those are reserved for internal use") if topic.start_with?('.')
|
52
52
|
raise TinyBus::SubscriberDoesNotMsg.new("The specified subscriber type `#{subber.class.inspect}' does not respond to #msg") unless subber.respond_to?(:msg)
|
53
53
|
|
54
54
|
@subs[topic] ||= Set.new
|
@@ -70,8 +70,11 @@ class TinyBus
|
|
70
70
|
# NOTE: it modifies the incoming msg object in place in order to avoid
|
71
71
|
# unnecessary object allocations
|
72
72
|
def msg(msg)
|
73
|
-
|
74
|
-
|
73
|
+
topic = msg['topic']
|
74
|
+
|
75
|
+
raise TinyBus::SendToDotTopicError.new("Cannot send to dot topic `#{topic}', because those are reserved for internal use") if topic.start_with?('.')
|
76
|
+
|
77
|
+
subbers = @subs[topic]
|
75
78
|
|
76
79
|
annotated = msg.merge!({
|
77
80
|
'.time' => Time.now.utc.iso8601(6),
|
@@ -79,12 +82,12 @@ class TinyBus
|
|
79
82
|
})
|
80
83
|
|
81
84
|
if subbers
|
82
|
-
@stats[
|
85
|
+
@stats[topic] += 1
|
83
86
|
subbers.each{|s| s.msg(annotated) }
|
84
87
|
@log.puts annotated
|
85
88
|
else
|
86
89
|
if @raise_on_dead
|
87
|
-
raise TinyBus::DeadMsgError.new("Could not deliver message to topic `#{
|
90
|
+
raise TinyBus::DeadMsgError.new("Could not deliver message to topic `#{topic}'")
|
88
91
|
else
|
89
92
|
@stats['.dead'] += 1
|
90
93
|
@dead.puts annotated
|
@@ -105,3 +108,4 @@ end
|
|
105
108
|
class TinyBus::DeadMsgError < RuntimeError; end
|
106
109
|
class TinyBus::SubscriptionToDotTopicError < RuntimeError; end
|
107
110
|
class TinyBus::SubscriberDoesNotMsg < RuntimeError; end
|
111
|
+
class TinyBus::SendToDotTopicError< RuntimeError; end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
@@ -24,9 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description:
|
28
|
-
distributes them out to subscribers based on a 'topic' key, with logging to $stdout
|
29
|
-
or a file, and absolutely nothing else? then this library is for you
|
27
|
+
description: a tiny pubsub message bus with almost no features
|
30
28
|
email: jefflunt@gmail.com
|
31
29
|
executables: []
|
32
30
|
extensions: []
|
@@ -55,5 +53,7 @@ requirements: []
|
|
55
53
|
rubygems_version: 3.0.3.1
|
56
54
|
signing_key:
|
57
55
|
specification_version: 4
|
58
|
-
summary:
|
56
|
+
summary: want to have an in-memory message bus that takes hash-like objects and distributes
|
57
|
+
them out to subscribers based on a 'topic' key, with logging to $stdout or a file,
|
58
|
+
and absolutely nothing else? then this library is for you
|
59
59
|
test_files: []
|