bps 0.0.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5de5e6e993f0b96c93224163f85fc0cd3ef5a9ecf7d03487df35315ee3bd153b
4
- data.tar.gz: cfaa3b821549d70bee5094321553123493d9e66fca4cf15fa50ccdb0f4c5a04d
3
+ metadata.gz: 98564c520e0bb883b77e9b9d696c2c3041b5d625f926f94d785999d2cefb3f9c
4
+ data.tar.gz: 04e13eb66946eaf205701d8e23746a724c76de67b4df0e87b93d61bb2e3407fd
5
5
  SHA512:
6
- metadata.gz: c4d068aa91b285af2a124a258a13207298c3c0f9202fe39f197e21a9fd49a53f433de12cf4817b78b265b2920deeaa402a014cba0fe74da3b258570688b8fb1e
7
- data.tar.gz: 4b7f0fa9bf89e079e05312e4d202af107b102c51079166704ca4641146942a0b3a692a0605d52bf0e46bbb8d8847b0969a8c8c20e763308d160988cff1c7d9c5
6
+ metadata.gz: 9dd1930a6e092846b01045e6061bd5a2c95b437b000c487adc042dac302db02f82a683ccfd2dcc5c383963c4e8b71e7eea2c96ec879216ab37ae8e748c8f7cd2
7
+ data.tar.gz: 71c7e4090b00818675db68864249f9259a06729c84ce88691d3cf6ac49caf40b9b013a15ce5e51a3cb2afe02383fdb3d579886d739b555b84f93131a5b7617f0
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
@@ -11,6 +11,10 @@ module BPS
11
11
  def flush(**); end
12
12
  end
13
13
 
14
+ def initialize
15
+ ObjectSpace.define_finalizer(self, proc { close })
16
+ end
17
+
14
18
  # Retrieve a topic handle.
15
19
  # @params [String] name the topic name.
16
20
  def topic(_name)
@@ -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
@@ -1,6 +1,10 @@
1
1
  module BPS
2
2
  module Subscriber
3
3
  class Abstract
4
+ def initialize
5
+ ObjectSpace.define_finalizer(self, proc { close })
6
+ end
7
+
4
8
  # Subscribe to a topic
5
9
  # @params [String] topic the topic name.
6
10
  def subscribe(_topic, **)
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe BPS::Publisher::InMem do
4
+ it 'should maintain topics' do
5
+ expect(subject.topic('x')).to be_a(described_class::Topic)
6
+ expect(subject.topic_names).to eq(%w[x])
7
+ expect(subject.topic('z')).to be_a(described_class::Topic)
8
+ expect(subject.topic_names).to eq(%w[x z])
9
+ expect(subject.topic('y')).to be_a(described_class::Topic)
10
+ expect(subject.topic_names).to eq(%w[x y z])
11
+ end
12
+
13
+ it 'should publish' do
14
+ topic = subject.topic('x')
15
+ topic.publish('foo')
16
+ topic.publish('bar')
17
+ expect(topic.messages).to eq(%w[foo bar])
18
+
19
+ expect { topic.flush }.not_to raise_error
20
+ expect(subject.topic('x').messages).to eq(%w[foo bar])
21
+ end
22
+ 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.1
4
+ version: 0.1.3
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: 2020-07-01 00:00:00.000000000 Z
11
+ date: 2020-11-24 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
@@ -41,9 +43,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
43
  - !ruby/object:Gem::Version
42
44
  version: '0'
43
45
  requirements: []
44
- rubygems_version: 3.1.4
46
+ rubygems_version: 3.1.2
45
47
  signing_key:
46
48
  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