tiny_bus 1.0.3 → 2.0.0

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 +10 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 167d35639547e4dd4a52b2882a02926cc7cc1b1e73c0ef2affaca995190f70a3
4
- data.tar.gz: 38326f77eba40699377e2b42f99e15484286c97028cdea5f35018d930f1fa18d
3
+ metadata.gz: 523256349438598095486d3bcdff8fc0df0c5c2375fef06402bd2385cbeb14e6
4
+ data.tar.gz: e832821fc355d7bf69a5378601bbc90c16439d683583b189d1f07be8481eccdf
5
5
  SHA512:
6
- metadata.gz: a588b106a52b799ab9c70f271ce2b4dc51fdac19f5b0518c53a95d5f5932b2eeda9ad53a5d61644e1d5aeba6ec0a0802540519ebbd21bc3e0c89f44ba8cd2ebd
7
- data.tar.gz: 61f2606e77ea63a9638fadc926d9c8020db234946271ed829b4b6d4e3d09115c6c260f81fca86830df1681363e1d002731fc63cba058d0311d6ab497c019fd24
6
+ metadata.gz: f7dc510d91314737850e511ab0e20b3c664ee8950766880a28b128f9b518fb0188acd0bd0c735ec7834c4c78650809f527352c42477fadaba1427f9c2714b127
7
+ data.tar.gz: fb351e69dacf513efc9198e67a3f6a5fd602f2d7924bcf7f1d3e5a9dfe62116892f360519d7863f6294b8aba65e56c9ee50796d7c6b7f9c5f68c4d8cf8494551
data/lib/tiny_bus.rb CHANGED
@@ -3,6 +3,8 @@ require 'set'
3
3
  require 'securerandom'
4
4
  require 'tiny_log'
5
5
 
6
+ # NOTE: This library depends on the TinyLog library.
7
+ #
6
8
  # This class implements a very simpler PubSub system where:
7
9
  # - subscribers can subscribe via the #sub method
8
10
  # - subscribers can unsubscribe via the #unsub method
@@ -25,11 +27,11 @@ require 'tiny_log'
25
27
  # TinyBus.new(raise_on_dead: true) # strict mode for undeliverable messages, defaults to false
26
28
  class TinyBus
27
29
  # log:
28
- # if specified it should be a valid filename
29
- # if not specified will default to $stdout
30
+ # if specified, it should be a TinyLog instance
31
+ # if not specified, it will create a new TinyLog instance for $stdout
30
32
  # dead:
31
- # if specified it should be a valid filename for dead letter logging
32
- # if not specified will default to $stderr
33
+ # if specified, it should be a TinyLog instance
34
+ # if not specified, it will create a new TinyLog instance for $stderr
33
35
  # raise_on_dead:
34
36
  # kind of a strict mode. if false, then messages with a topic with no
35
37
  # subscribers will go to the dead file. if true, then messages with a topic
@@ -37,8 +39,8 @@ class TinyBus
37
39
  def initialize(log: nil, dead: nil, raise_on_dead: false)
38
40
  @subs = {}
39
41
  @stats = { '.dead' => 0 }
40
- @log = log ? TinyLog.new(log) : TinyLog.new($stdout)
41
- @dead = dead ? File.open(dead, 'a') : TinyLog.new($stderr)
42
+ @log = log || TinyLog.new($stdout)
43
+ @dead = dead || TinyLog.new($stderr)
42
44
  @raise_on_dead = raise_on_dead
43
45
  end
44
46
 
@@ -84,13 +86,13 @@ class TinyBus
84
86
  if subbers
85
87
  @stats[topic] += 1
86
88
  subbers.each{|s| s.msg(annotated) }
87
- @log.send(lvl, annotated)
89
+ @log.sent annotated
88
90
  else
89
91
  if @raise_on_dead
90
92
  raise TinyBus::DeadMsgError.new("Could not deliver message to topic `#{topic}'")
91
93
  else
92
94
  @stats['.dead'] += 1
93
- @dead.send(lvl, annotated)
95
+ @dead.dead annotated
94
96
  end
95
97
  end
96
98
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-18 00:00:00.000000000 Z
11
+ date: 2022-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tiny_log