tiny_bus 1.0.2 → 1.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tiny_bus.rb +8 -8
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb6142b34ec3c5c72a2a4073b080d8aba77dd40b9c04df3df89d9802a26c5c39
4
- data.tar.gz: b94962edf28bd4ad4affecb69cfd6d68d298b6623b98518cbbc9059fc117c83d
3
+ metadata.gz: 167d35639547e4dd4a52b2882a02926cc7cc1b1e73c0ef2affaca995190f70a3
4
+ data.tar.gz: 38326f77eba40699377e2b42f99e15484286c97028cdea5f35018d930f1fa18d
5
5
  SHA512:
6
- metadata.gz: 1a29c06a16aab93b03d5a68384c55a4f461dd2a5e3b06c888d0d420325cd169dd1a16284af10a467eeb6953a525a809287deed3b25781a831ade89847d8dd0aa
7
- data.tar.gz: 05de4ca2e32edad9a3d63a065752c1990135d5de66710f957dfbc49838a6f45e2ffb9b4c901f831a073bbf14dd4a5291ef62c9d96a9219a9021c4a32f197176b
6
+ metadata.gz: a588b106a52b799ab9c70f271ce2b4dc51fdac19f5b0518c53a95d5f5932b2eeda9ad53a5d61644e1d5aeba6ec0a0802540519ebbd21bc3e0c89f44ba8cd2ebd
7
+ data.tar.gz: 61f2606e77ea63a9638fadc926d9c8020db234946271ed829b4b6d4e3d09115c6c260f81fca86830df1681363e1d002731fc63cba058d0311d6ab497c019fd24
data/lib/tiny_bus.rb CHANGED
@@ -20,9 +20,9 @@ require 'tiny_log'
20
20
  # t.msg({'topic' => 'whatever', 'details' => 'Historic happenings!}) # goes to dead letter output, or raises exception, depending on the configuration
21
21
  #
22
22
  # Initialization options:
23
- # TinyBus.new(log: <some object that responds to #puts>) # will send a copy of all successful messages to the log
24
- # TinyBus.new(dead: <some object that responds to #puts>) # will send a copy of all unsuccessful messages to the dead object
25
- # TinyBus.new(raise_on_dead: true) # strict mode for undeliverable messages, defaults to false
23
+ # TinyBus.new(log: <a filename for log output>) # will log all normal msgs in this file
24
+ # TinyBus.new(dead: <a filename for dead message log output>) # will log all undeliverable msgs in this file
25
+ # TinyBus.new(raise_on_dead: true) # strict mode for undeliverable messages, defaults to false
26
26
  class TinyBus
27
27
  # log:
28
28
  # if specified it should be a valid filename
@@ -37,8 +37,8 @@ class TinyBus
37
37
  def initialize(log: nil, dead: nil, raise_on_dead: false)
38
38
  @subs = {}
39
39
  @stats = { '.dead' => 0 }
40
- @log = log ? TinyLog.new(log) : $stdout
41
- @dead = dead ? File.open(dead, 'a') : $stderr
40
+ @log = log ? TinyLog.new(log) : TinyLog.new($stdout)
41
+ @dead = dead ? File.open(dead, 'a') : TinyLog.new($stderr)
42
42
  @raise_on_dead = raise_on_dead
43
43
  end
44
44
 
@@ -69,7 +69,7 @@ class TinyBus
69
69
  #
70
70
  # NOTE: it modifies the incoming msg object in place in order to avoid
71
71
  # unnecessary object allocations
72
- def msg(msg)
72
+ def msg(msg, lvl='info')
73
73
  topic = msg['topic']
74
74
 
75
75
  raise TinyBus::SendToDotTopicError.new("Cannot send to dot topic `#{topic}', because those are reserved for internal use") if topic.start_with?('.')
@@ -84,13 +84,13 @@ class TinyBus
84
84
  if subbers
85
85
  @stats[topic] += 1
86
86
  subbers.each{|s| s.msg(annotated) }
87
- @log.puts annotated
87
+ @log.send(lvl, annotated)
88
88
  else
89
89
  if @raise_on_dead
90
90
  raise TinyBus::DeadMsgError.new("Could not deliver message to topic `#{topic}'")
91
91
  else
92
92
  @stats['.dead'] += 1
93
- @dead.puts annotated
93
+ @dead.send(lvl, annotated)
94
94
  end
95
95
  end
96
96
  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.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt