bps 0.0.2 → 0.2.0
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/bps.rb +3 -2
- data/lib/bps/publisher/abstract.rb +4 -0
- data/lib/bps/publisher/in_mem.rb +41 -0
- data/lib/bps/subscriber/abstract.rb +4 -0
- data/spec/bps/coercer_spec.rb +6 -5
- data/spec/bps/publisher/in_mem_spec.rb +26 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3cb827d3fac93c3b7d2d2b76e91bee0b7f7569b737477dad2c57c2c08abd389
|
4
|
+
data.tar.gz: 462fc0049318f7543e951ed88c9fedf82e343f17b376e7aca8f02f1e53792ec1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5bb4bc4e8080c51feac74ebad02833acf9f26c5484e194987f9de44914c50507e790ea0285628f70624cdef454d5e9bd8bd9d81986c2d15fec38acfcdff0bb7
|
7
|
+
data.tar.gz: 6ed7587f48822c71b86ab8890159a3a7f40a235cf598d998df29d37c48d61cef2c8c4746a1eeec4316cbf246a1570fae5f4f081d8c16cca545300df3a05851e7
|
data/lib/bps.rb
CHANGED
@@ -6,6 +6,7 @@ module BPS
|
|
6
6
|
|
7
7
|
module Publisher
|
8
8
|
autoload :Abstract, 'bps/publisher/abstract'
|
9
|
+
autoload :InMem, 'bps/publisher/in_mem'
|
9
10
|
|
10
11
|
def self.register(*schemes, &resolver)
|
11
12
|
@registry ||= {}
|
@@ -23,7 +24,7 @@ module BPS
|
|
23
24
|
CGI.parse(url.query.to_s).each do |key, values|
|
24
25
|
opts[key.to_sym] = values.first
|
25
26
|
end
|
26
|
-
rsl.call(url, opts)
|
27
|
+
rsl.call(url, **opts)
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
@@ -46,7 +47,7 @@ module BPS
|
|
46
47
|
CGI.parse(url.query.to_s).each do |key, values|
|
47
48
|
opts[key.to_sym] = values.first
|
48
49
|
end
|
49
|
-
rsl.call(url, opts)
|
50
|
+
rsl.call(url, **opts)
|
50
51
|
end
|
51
52
|
end
|
52
53
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module BPS
|
2
|
+
module Publisher
|
3
|
+
class InMem < Abstract
|
4
|
+
class Topic < Abstract::Topic
|
5
|
+
attr_reader :name, :messages
|
6
|
+
|
7
|
+
def initialize(name)
|
8
|
+
super()
|
9
|
+
@name = name.to_s
|
10
|
+
@messages = []
|
11
|
+
end
|
12
|
+
|
13
|
+
# Publish a message.
|
14
|
+
def publish(message, **)
|
15
|
+
@messages.push(message.to_s)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
super()
|
21
|
+
@topics = {}
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Array<String>] the existing topic names.
|
25
|
+
def topic_names
|
26
|
+
@topic_names ||= @topics.keys.sort
|
27
|
+
end
|
28
|
+
|
29
|
+
# Retrieve a topic handle.
|
30
|
+
# @params [String] name the topic name.
|
31
|
+
def topic(name)
|
32
|
+
name = name.to_s
|
33
|
+
|
34
|
+
@topics[name] ||= begin
|
35
|
+
@topic_names = nil
|
36
|
+
self.class::Topic.new(name)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/bps/coercer_spec.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe BPS::Coercer do
|
4
|
-
subject
|
4
|
+
subject { coercer }
|
5
|
+
|
6
|
+
let(:coercer) do
|
5
7
|
described_class.new(
|
6
8
|
name: :string,
|
7
9
|
codec: :symbol,
|
@@ -11,7 +13,6 @@ RSpec.describe BPS::Coercer do
|
|
11
13
|
tags: [:string],
|
12
14
|
)
|
13
15
|
end
|
14
|
-
|
15
16
|
let :options do
|
16
17
|
{
|
17
18
|
name: 123,
|
@@ -24,13 +25,13 @@ RSpec.describe BPS::Coercer do
|
|
24
25
|
}
|
25
26
|
end
|
26
27
|
|
27
|
-
it '
|
28
|
+
it 'validates' do
|
28
29
|
expect { described_class.new(name: :unknown) }.to raise_error(ArgumentError, /Unknown type :unknown/)
|
29
30
|
expect { described_class.new(bad: []) }.to raise_error(ArgumentError, /Array types must have exactly one entry/)
|
30
31
|
end
|
31
32
|
|
32
|
-
it '
|
33
|
-
expect(
|
33
|
+
it 'coerces options' do
|
34
|
+
expect(coercer.coerce(options)).to eq(
|
34
35
|
name: '123',
|
35
36
|
codec: :snappy,
|
36
37
|
retries: 4,
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe BPS::Publisher::InMem do
|
4
|
+
subject { publisher }
|
5
|
+
|
6
|
+
let(:publisher) { described_class.new }
|
7
|
+
|
8
|
+
it 'maintains topics' do
|
9
|
+
expect(publisher.topic('x')).to be_a(described_class::Topic)
|
10
|
+
expect(publisher.topic_names).to eq(%w[x])
|
11
|
+
expect(publisher.topic('z')).to be_a(described_class::Topic)
|
12
|
+
expect(publisher.topic_names).to eq(%w[x z])
|
13
|
+
expect(publisher.topic('y')).to be_a(described_class::Topic)
|
14
|
+
expect(publisher.topic_names).to eq(%w[x y z])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'publishes' do
|
18
|
+
topic = publisher.topic('x')
|
19
|
+
topic.publish('foo')
|
20
|
+
topic.publish('bar')
|
21
|
+
expect(topic.messages).to eq(%w[foo bar])
|
22
|
+
|
23
|
+
expect { topic.flush }.not_to raise_error
|
24
|
+
expect(publisher.topic('x').messages).to eq(%w[foo bar])
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Black Square Media
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Minimalist abstraction for publish-subscribe
|
14
14
|
email: info@blacksquaremedia.com
|
@@ -20,8 +20,10 @@ files:
|
|
20
20
|
- lib/bps.rb
|
21
21
|
- lib/bps/coercer.rb
|
22
22
|
- lib/bps/publisher/abstract.rb
|
23
|
+
- lib/bps/publisher/in_mem.rb
|
23
24
|
- lib/bps/subscriber/abstract.rb
|
24
25
|
- spec/bps/coercer_spec.rb
|
26
|
+
- spec/bps/publisher/in_mem_spec.rb
|
25
27
|
homepage: https://github.com/bsm/bps
|
26
28
|
licenses:
|
27
29
|
- Apache-2.0
|
@@ -47,3 +49,4 @@ specification_version: 4
|
|
47
49
|
summary: Multi-platform pubsub adapter
|
48
50
|
test_files:
|
49
51
|
- spec/bps/coercer_spec.rb
|
52
|
+
- spec/bps/publisher/in_mem_spec.rb
|