tiny_bus 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tiny_bus.rb +9 -5
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4d536f5d26c59f828baf005884e8d6be51596b61c151a2c77e129c2a1f80305
4
- data.tar.gz: 885f08feed148a3808dfde24a38871544e01ac82fe27114ef8000e7fe0f8a630
3
+ metadata.gz: fb6142b34ec3c5c72a2a4073b080d8aba77dd40b9c04df3df89d9802a26c5c39
4
+ data.tar.gz: b94962edf28bd4ad4affecb69cfd6d68d298b6623b98518cbbc9059fc117c83d
5
5
  SHA512:
6
- metadata.gz: 8ead2a2d5889921a3544a8ffc91fe93929bb3a52efe3edd1de14c0046533641f7a170f1de32b065cdeb19984d007904a6ef391a9b58fcb61839baf557868a33e
7
- data.tar.gz: 453bd1af26f50d84155a45ba454f66fbdf1cd83b6418cd0543120c3a012a0f91738d6109faea9f983656ed4bdd2ebf0992de95ca449fc3fcbeb0b154a008bd6c
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 these are reserved for internal use") if topic.start_with?('.')
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
- t = msg['topic']
74
- subbers = @subs[t]
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[t] += 1
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 `#{t}'")
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.1
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: want to have an in-memory message bus that takes hash-like objects and
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: a tiny pubsub message bus with almost no features
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: []