wisper 2.0.1 → 3.0.0.rc1

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: 2890739bfde16edeb614504b6a6ac9f1babe148c3ed3255af7b11d2b68275dc8
4
- data.tar.gz: f64460470b4778927d19bbab51f5cd190ec2d16df4909340ee09aaa89b8e9636
3
+ metadata.gz: 051745d94baf4c2ba328de627fde2f5bea42ed5081e2c830520b5ee33bef9c28
4
+ data.tar.gz: b069da8aa786e36d2fe0f51f90030295a9a918f5b8733341515e5c93dca92d7b
5
5
  SHA512:
6
- metadata.gz: 82292503201b5402aebb60c3ad433c4f1bfb22858fbd1221ba86225dbb9e597f2ffb97c8b075847a12c5a801fb92d7e84a9485fb8919c39548f80e54c2fdf318
7
- data.tar.gz: b40625e6e3cf17df8a457f6547ecf5f0d921ff7dc771910462d0a5219d2aba9ab0afcc91787cdb5ccd49d18f48845eda3b95f20ef9bdd4914d1afca5c2f45f4c
6
+ metadata.gz: 4c84a5d089a16c2588a3cf2d1c83100ff5bc0a7db191c63e47251a4c7e3c8214ddca68a6f2a06e4b155077f88fb3f78e94537c4fe4e0fd68c5ff72cad929a66c
7
+ data.tar.gz: 628455d61676ea7618979695ef6a5babe5654db083162f3c5db9aa5dd833b4ff351b4e27f23730b19b7fb07fb4c440fc51857147657657bde941b37465164a91
checksums.yaml.gz.sig CHANGED
Binary file
@@ -0,0 +1,17 @@
1
+ name: Run unit tests
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ os: [ubuntu-latest]
9
+ ruby: ["2.7", "3.0", "3.1", "3.2", "jruby"]
10
+ runs-on: ${{ matrix.os }}
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: ${{ matrix.ruby }}
16
+ bundler-cache: true
17
+ - run: bundle exec rspec spec
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  .bundle
5
5
  .config
6
6
  .yardoc
7
+ .tool-versions
7
8
  Gemfile.lock
8
9
  InstalledFiles
9
10
  _yardoc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## HEAD (unreleased)
2
2
 
3
+ ## 3.0.0.rc1 (6th July 2023)
4
+
5
+ Authors: Keith Bennett, doits, jstoks, merringtion, thirunjuguna
6
+
7
+ * fix: exclude bin directory from gem #181
8
+ * Adds: Support for Ruby 3.0 keyword arguments
9
+ * Removes: Support for Ruby 2.6 and lower [breaking change]
10
+
3
11
  ## 2.0.1 (29th Aug 2019)
4
12
 
5
13
  Authors: David Wilkie, hosseintoussi, Maxim Polunin, Tristan
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/wisper.svg)](http://badge.fury.io/rb/wisper)
6
6
  [![Code Climate](https://codeclimate.com/github/krisleech/wisper.svg)](https://codeclimate.com/github/krisleech/wisper)
7
- [![Build Status](https://travis-ci.org/krisleech/wisper.svg?branch=master)](https://travis-ci.org/krisleech/wisper)
7
+ [![Build Status](https://github.com/krisleech/wisper/actions/workflows/test.yml/badge.svg)](https://github.com/krisleech/wisper/actions)
8
8
  [![Coverage Status](https://coveralls.io/repos/krisleech/wisper/badge.svg?branch=master)](https://coveralls.io/r/krisleech/wisper?branch=master)
9
9
 
10
10
  * Decouple core business logic from external concerns in Hexagonal style architectures
@@ -16,12 +16,15 @@ Note: Wisper was originally extracted from a Rails codebase but is not dependant
16
16
 
17
17
  Please also see the [Wiki](https://github.com/krisleech/wisper/wiki) for more additional information and articles.
18
18
 
19
+ **For greenfield applications you might also be interested in
20
+ [WisperNext](https://gitlab.com/kris.leech/wisper_next) and [Ma](https://gitlab.com/kris.leech/ma).**
21
+
19
22
  ## Installation
20
23
 
21
24
  Add this line to your application's Gemfile:
22
25
 
23
26
  ```ruby
24
- gem 'wisper', '2.0.0'
27
+ gem 'wisper', '~3.0'
25
28
  ```
26
29
 
27
30
  ## Usage
@@ -194,7 +197,14 @@ This is useful for cross cutting concerns such as recording statistics, indexing
194
197
  Wisper.subscribe(MyListener.new)
195
198
  ```
196
199
 
197
- In a Rails app you might want to add your global listeners in an initializer.
200
+ In a Rails app you might want to add your global listeners in an initializer like:
201
+
202
+ ```ruby
203
+ # config/initializers/listeners.rb
204
+ Rails.application.reloader.to_prepare do
205
+ Wisper.subscribe(MyListener.new)
206
+ end
207
+ ```
198
208
 
199
209
  Global listeners are threadsafe. Subscribers will receive events published on all threads.
200
210
 
@@ -319,9 +329,7 @@ Got a specific question, try the
319
329
 
320
330
  ## Compatibility
321
331
 
322
- Tested with MRI 2.x, JRuby and Rubinius.
323
-
324
- See the [build status](https://travis-ci.org/krisleech/wisper) for details.
332
+ See the [build status](https://github.com/krisleech/wisper/actions) for details.
325
333
 
326
334
  ## Running Specs
327
335
 
data/gem-public_cert.pem CHANGED
@@ -1,20 +1,19 @@
1
1
  -----BEGIN CERTIFICATE-----
2
- MIIDQDCCAiigAwIBAgIBATANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBprcmlz
3
- LmxlZWNoL0RDPWdtYWlsL0RDPWNvbTAeFw0xOTEwMTYxNDEzNDVaFw0yMDEwMTUx
4
- NDEzNDVaMCUxIzAhBgNVBAMMGmtyaXMubGVlY2gvREM9Z21haWwvREM9Y29tMIIB
2
+ MIIC/jCCAeagAwIBAgIBAjANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBprcmlz
3
+ LmxlZWNoL0RDPWdtYWlsL0RDPWNvbTAeFw0yMzA3MDYxNTI0MDdaFw0yNDA3MDUx
4
+ NTI0MDdaMCUxIzAhBgNVBAMMGmtyaXMubGVlY2gvREM9Z21haWwvREM9Y29tMIIB
5
5
  IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8gg/iZE6RFkl6GjisJJf9wQl
6
6
  5Tog+mrGqtylNpe9QKeyQS1fKLNR3Cqmv6sT3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4ADQ8ANOFF0dCDPPsEn6qMhf
14
+ cNEbRQhMexbe5xQTRVey+20i6vvnJ/kwqnftxAm28Jc3QMMsPk+iM2HZiOsBzICj
15
+ b7k2mPBUf3M6aj8i2fRo6H79PsAN3y7AyU9/KhgkcwHQhr+k7kFpnXKMNlw02ctg
16
+ nzy6xfYdDTzcw47twNBWr53COJTJMgdmlVupROoNjQsJTvuSfUiuy5JFGqS0fijB
17
+ tiGTXMVCk/fOTj04HvFZi/P11KUmQ6HsevziemEgQOnG2lCp+BkyNN0Y4XVW/mno
18
+ x7Y=
20
19
  -----END CERTIFICATE-----
@@ -8,9 +8,9 @@ module Wisper
8
8
  @broadcaster = broadcaster
9
9
  end
10
10
 
11
- def broadcast(listener, publisher, event, args)
12
- @logger.info("[WISPER] #{name(publisher)} published #{event} to #{name(listener)} with #{args_info(args)}")
13
- @broadcaster.broadcast(listener, publisher, event, args)
11
+ def broadcast(listener, publisher, event, *args, **kwargs)
12
+ @logger.info("[WISPER] #{name(publisher)} published #{event} to #{name(listener)} with #{args_info(args)} and #{kwargs_info(kwargs)}")
13
+ @broadcaster.broadcast(listener, publisher, event, *args, **kwargs)
14
14
  end
15
15
 
16
16
  private
@@ -32,6 +32,10 @@ module Wisper
32
32
  arg_string
33
33
  end.join(', ')
34
34
  end
35
+
36
+ def kwargs_info(kwargs)
37
+ kwargs.empty? ? 'no keyword arguments' : "keyword arguments #{kwargs.inspect}"
38
+ end
35
39
  end
36
40
  end
37
41
  end
@@ -1,8 +1,8 @@
1
1
  module Wisper
2
2
  module Broadcasters
3
3
  class SendBroadcaster
4
- def broadcast(listener, publisher, event, args)
5
- listener.public_send(event, *args)
4
+ def broadcast(listener, publisher, event, *args, **kwargs)
5
+ listener.public_send(event, *args, **kwargs)
6
6
  end
7
7
  end
8
8
  end
@@ -13,12 +13,10 @@ module Wisper
13
13
  @mutex = Mutex.new
14
14
  end
15
15
 
16
- def subscribe(*listeners)
17
- options = listeners.last.is_a?(Hash) ? listeners.pop : {}
18
-
16
+ def subscribe(*listeners, **options)
19
17
  with_mutex do
20
18
  listeners.each do |listener|
21
- @registrations << ObjectRegistration.new(listener, options)
19
+ @registrations << ObjectRegistration.new(listener, **options)
22
20
  end
23
21
  end
24
22
  self
@@ -45,8 +43,8 @@ module Wisper
45
43
  with_mutex { @registrations.clear }
46
44
  end
47
45
 
48
- def self.subscribe(*listeners)
49
- instance.subscribe(*listeners)
46
+ def self.subscribe(*listeners, **options)
47
+ instance.subscribe(*listeners, **options)
50
48
  end
51
49
 
52
50
  def self.unsubscribe(*listeners)
@@ -10,9 +10,9 @@ module Wisper
10
10
  # my_publisher.subscribe(MyListener.new)
11
11
  #
12
12
  # @return [self]
13
- def subscribe(listener, options = {})
13
+ def subscribe(listener, **options)
14
14
  raise ArgumentError, "#{__method__} does not take a block, did you mean to call #on instead?" if block_given?
15
- local_registrations << ObjectRegistration.new(listener, options)
15
+ local_registrations << ObjectRegistration.new(listener, **options)
16
16
  self
17
17
  end
18
18
 
@@ -38,9 +38,9 @@ module Wisper
38
38
  # end
39
39
  #
40
40
  # @return [self]
41
- def broadcast(event, *args)
41
+ def broadcast(event, *args, **kwargs)
42
42
  registrations.each do | registration |
43
- registration.broadcast(clean_event(event), self, *args)
43
+ registration.broadcast(clean_event(event), self, *args, **kwargs)
44
44
  end
45
45
  self
46
46
  end
@@ -55,8 +55,8 @@ module Wisper
55
55
  # @example
56
56
  # MyPublisher.subscribe(MyListener.new)
57
57
  #
58
- def subscribe(listener, options = {})
59
- GlobalListeners.subscribe(listener, options.merge(:scope => self))
58
+ def subscribe(listener, **options)
59
+ GlobalListeners.subscribe(listener, **options.merge(:scope => self))
60
60
  end
61
61
  end
62
62
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Wisper
4
4
  class BlockRegistration < Registration
5
- def broadcast(event, publisher, *args)
5
+ def broadcast(event, publisher, *args, **kwargs)
6
6
  if should_broadcast?(event)
7
- listener.call(*args)
7
+ listener.call(*args, **kwargs)
8
8
  end
9
9
  end
10
10
  end
@@ -4,18 +4,18 @@ module Wisper
4
4
  class ObjectRegistration < Registration
5
5
  attr_reader :with, :prefix, :allowed_classes, :broadcaster
6
6
 
7
- def initialize(listener, options)
8
- super(listener, options)
7
+ def initialize(listener, **options)
8
+ super(listener, **options)
9
9
  @with = options[:with]
10
10
  @prefix = ValueObjects::Prefix.new options[:prefix]
11
11
  @allowed_classes = Array(options[:scope]).map(&:to_s).to_set
12
12
  @broadcaster = map_broadcaster(options[:async] || options[:broadcaster])
13
13
  end
14
14
 
15
- def broadcast(event, publisher, *args)
15
+ def broadcast(event, publisher, *args, **kwargs)
16
16
  method_to_call = map_event_to_method(event)
17
17
  if should_broadcast?(event) && listener.respond_to?(method_to_call) && publisher_in_scope?(publisher)
18
- broadcaster.broadcast(listener, publisher, method_to_call, args)
18
+ broadcaster.broadcast(listener, publisher, method_to_call, *args, **kwargs)
19
19
  end
20
20
  end
21
21
 
@@ -4,7 +4,7 @@ module Wisper
4
4
  class Registration
5
5
  attr_reader :on, :listener
6
6
 
7
- def initialize(listener, options)
7
+ def initialize(listener, **options)
8
8
  @listener = listener
9
9
  @on = ValueObjects::Events.new options[:on]
10
10
  end
@@ -4,16 +4,16 @@
4
4
 
5
5
  module Wisper
6
6
  class TemporaryListeners
7
- def self.subscribe(*listeners, &block)
8
- new.subscribe(*listeners, &block)
7
+ def self.subscribe(*listeners, **options, &block)
8
+ new.subscribe(*listeners, **options, &block)
9
9
  end
10
10
 
11
11
  def self.registrations
12
12
  new.registrations
13
13
  end
14
14
 
15
- def subscribe(*listeners, &_block)
16
- new_registrations = build_registrations(listeners)
15
+ def subscribe(*listeners, **options, &_block)
16
+ new_registrations = build_registrations(*listeners, **options)
17
17
 
18
18
  begin
19
19
  registrations.merge new_registrations
@@ -30,9 +30,8 @@ module Wisper
30
30
 
31
31
  private
32
32
 
33
- def build_registrations(listeners)
34
- options = listeners.last.is_a?(Hash) ? listeners.pop : {}
35
- listeners.map { |listener| ObjectRegistration.new(listener, options) }
33
+ def build_registrations(*listeners, **options)
34
+ listeners.map { |listener| ObjectRegistration.new(listener, **options) }
36
35
  end
37
36
 
38
37
  def key
@@ -1,3 +1,3 @@
1
1
  module Wisper
2
- VERSION = "2.0.1"
2
+ VERSION = "3.0.0.rc1"
3
3
  end
data/lib/wisper.rb CHANGED
@@ -27,11 +27,11 @@ module Wisper
27
27
  # # ..
28
28
  # end
29
29
  #
30
- def self.subscribe(*args, &block)
30
+ def self.subscribe(*args, **kwargs, &block)
31
31
  if block_given?
32
- TemporaryListeners.subscribe(*args, &block)
32
+ TemporaryListeners.subscribe(*args, **kwargs, &block)
33
33
  else
34
- GlobalListeners.subscribe(*args)
34
+ GlobalListeners.subscribe(*args, **kwargs)
35
35
  end
36
36
  end
37
37
 
@@ -15,7 +15,7 @@ describe Wisper do
15
15
 
16
16
  it 'subscribes object to all published events' do
17
17
  listener = double('listener')
18
- expect(listener).to receive(:success).with('hello')
18
+ expect(listener).to receive(:success).with('hello', **{})
19
19
 
20
20
  command = MyCommand.new
21
21
 
@@ -27,8 +27,8 @@ describe Wisper do
27
27
  it 'maps events to different methods' do
28
28
  listener_1 = double('listener')
29
29
  listener_2 = double('listener')
30
- expect(listener_1).to receive(:happy_days).with('hello')
31
- expect(listener_2).to receive(:sad_days).with('world')
30
+ expect(listener_1).to receive(:happy_days).with('hello', **{})
31
+ expect(listener_2).to receive(:sad_days).with('world', **{})
32
32
 
33
33
  command = MyCommand.new
34
34
 
@@ -11,8 +11,8 @@ end
11
11
  describe 'simple publishing' do
12
12
  it 'subscribes listener to events' do
13
13
  listener = double('listener')
14
- expect(listener).to receive(:foo).with instance_of MyPublisher
15
- expect(listener).to receive(:bar).with instance_of MyPublisher
14
+ expect(listener).to receive(:foo).with((instance_of MyPublisher), **{})
15
+ expect(listener).to receive(:bar).with((instance_of MyPublisher), **{})
16
16
 
17
17
  my_publisher = MyPublisher.new
18
18
  my_publisher.subscribe(listener)
@@ -8,10 +8,34 @@ module Wisper
8
8
  let(:listener) { double }
9
9
  let(:logger) { double.as_null_object }
10
10
 
11
- it 'broadcasts the event to the listener' do
12
- publisher.subscribe(listener, :broadcaster => LoggerBroadcaster.new(logger, Wisper::Broadcasters::SendBroadcaster.new))
13
- expect(listener).to receive(:it_happened).with(1, 2)
14
- publisher.send(:broadcast, :it_happened, 1, 2)
11
+ context 'with only positional arguments' do
12
+ it 'broadcasts the event to the listener' do
13
+ publisher.subscribe(listener, :broadcaster => LoggerBroadcaster.new(logger, Wisper::Broadcasters::SendBroadcaster.new))
14
+ if RUBY_VERSION < '3.0'
15
+ # Ruby 2.7 receives **{} as a positional argument
16
+ expect(listener).to receive(:it_happened).with(1, 2, {})
17
+ else
18
+ # Ruby 3.0 doesn't pass **empty_hash
19
+ expect(listener).to receive(:it_happened).with(1, 2)
20
+ end
21
+ publisher.send(:broadcast, :it_happened, 1, 2)
22
+ end
23
+ end
24
+
25
+ context 'with only keyword arguments' do
26
+ it 'broadcasts the event to the listener' do
27
+ publisher.subscribe(listener, :broadcaster => LoggerBroadcaster.new(logger, Wisper::Broadcasters::SendBroadcaster.new))
28
+ expect(listener).to receive(:it_happened).with(key: 'value')
29
+ publisher.send(:broadcast, :it_happened, key: 'value')
30
+ end
31
+ end
32
+
33
+ context 'with positional and keyword arguments' do
34
+ it 'broadcasts the event to the listener' do
35
+ publisher.subscribe(listener, :broadcaster => LoggerBroadcaster.new(logger, Wisper::Broadcasters::SendBroadcaster.new))
36
+ expect(listener).to receive(:it_happened).with(1, 2, key: 'value')
37
+ publisher.send(:broadcast, :it_happened, 1, 2, key: 'value')
38
+ end
15
39
  end
16
40
  end
17
41
 
@@ -27,38 +51,41 @@ module Wisper
27
51
  describe '#broadcast' do
28
52
  context 'without arguments' do
29
53
  let(:args) { [] }
54
+ let(:kwargs) { {} }
30
55
 
31
56
  it 'logs published event' do
32
- expect(logger).to receive(:info).with('[WISPER] Publisher#1 published thing_created to Listener#2 with no arguments')
33
- subject.broadcast(listener, publisher, event, args)
57
+ expect(logger).to receive(:info).with('[WISPER] Publisher#1 published thing_created to Listener#2 with no arguments and no keyword arguments')
58
+ subject.broadcast(listener, publisher, event, *args, **kwargs)
34
59
  end
35
60
 
36
61
  it 'delegates broadcast to a given broadcaster' do
37
- expect(broadcaster).to receive(:broadcast).with(listener, publisher, event, args)
38
- subject.broadcast(listener, publisher, event, args)
62
+ expect(broadcaster).to receive(:broadcast).with(listener, publisher, event, *args, **kwargs)
63
+ subject.broadcast(listener, publisher, event, *args, **kwargs)
39
64
  end
40
65
  end
41
66
 
42
67
  context 'with arguments' do
43
68
  let(:args) { [arg_double(id: 3), arg_double(id: 4)] }
69
+ let(:kwargs) { {x: :y} }
44
70
 
45
71
  it 'logs published event and arguments' do
46
- expect(logger).to receive(:info).with('[WISPER] Publisher#1 published thing_created to Listener#2 with Argument#3, Argument#4')
47
- subject.broadcast(listener, publisher, event, args)
72
+ expect(logger).to receive(:info).with("[WISPER] Publisher#1 published thing_created to Listener#2 with Argument#3, Argument#4 and keyword arguments {:x=>:y}")
73
+ subject.broadcast(listener, publisher, event, *args, **kwargs)
48
74
  end
49
75
 
50
76
  it 'delegates broadcast to a given broadcaster' do
51
- expect(broadcaster).to receive(:broadcast).with(listener, publisher, event, args)
52
- subject.broadcast(listener, publisher, event, args)
77
+ expect(broadcaster).to receive(:broadcast).with(listener, publisher, event, *args, **kwargs)
78
+ subject.broadcast(listener, publisher, event, *args, **kwargs)
53
79
  end
54
80
 
55
81
  context 'when argument is a hash' do
56
82
  let(:args) { [hash] }
57
83
  let(:hash) { {key: 'value'} }
84
+ let(:kwargs) { {x: :y} }
58
85
 
59
86
  it 'logs published event and arguments' do
60
- expect(logger).to receive(:info).with("[WISPER] Publisher#1 published thing_created to Listener#2 with Hash##{hash.object_id}: #{hash.inspect}")
61
- subject.broadcast(listener, publisher, event, args)
87
+ expect(logger).to receive(:info).with("[WISPER] Publisher#1 published thing_created to Listener#2 with Hash##{hash.object_id}: #{hash.inspect} and keyword arguments {:x=>:y}")
88
+ subject.broadcast(listener, publisher, event, *args, **kwargs)
62
89
  end
63
90
  end
64
91
 
@@ -67,8 +94,17 @@ module Wisper
67
94
  let(:number) { 10 }
68
95
 
69
96
  it 'logs published event and arguments' do
70
- expect(logger).to receive(:info).with("[WISPER] Publisher#1 published thing_created to Listener#2 with #{number.class.name}##{number.object_id}: 10")
71
- subject.broadcast(listener, publisher, event, args)
97
+ expect(logger).to receive(:info).with("[WISPER] Publisher#1 published thing_created to Listener#2 with #{number.class.name}##{number.object_id}: 10 and keyword arguments {:x=>:y}")
98
+ subject.broadcast(listener, publisher, event, *args, **kwargs)
99
+ end
100
+ end
101
+
102
+ context 'when only keyword arguments are present' do
103
+ let(:args) { [] }
104
+
105
+ it 'logs published event and arguments' do
106
+ expect(logger).to receive(:info).with("[WISPER] Publisher#1 published thing_created to Listener#2 with no arguments and keyword arguments {:x=>:y}")
107
+ subject.broadcast(listener, publisher, event, *args, **kwargs)
72
108
  end
73
109
  end
74
110
  end
@@ -6,20 +6,60 @@ module Wisper
6
6
 
7
7
  describe '#broadcast' do
8
8
  context 'without arguments' do
9
+ it 'sends event to listener without any arguments' do
10
+ if RUBY_VERSION < '3.0'
11
+ expect(listener).to receive(event).with({})
12
+ else
13
+ expect(listener).to receive(event).with(no_args)
14
+ end
15
+ subject.broadcast(listener, anything, event)
16
+ end
17
+ end
18
+
19
+ context 'with empty arguments' do
9
20
  let(:args) { [] }
10
21
 
11
22
  it 'sends event to listener without any arguments' do
12
- expect(listener).to receive(event).with(no_args())
13
- subject.broadcast(listener, anything, event, args)
23
+ if RUBY_VERSION < '3.0'
24
+ expect(listener).to receive(event).with({})
25
+ else
26
+ expect(listener).to receive(event).with(no_args)
27
+ end
28
+ subject.broadcast(listener, anything, event, *args)
14
29
  end
15
30
  end
16
31
 
17
32
  context 'with arguments' do
18
- let(:args) { [1,2,3] }
33
+ context 'with only positional arguments' do
34
+ let(:args) { [1,2,3] }
35
+
36
+ it 'sends event to listener with arguments' do
37
+ if RUBY_VERSION < '3.0'
38
+ expect(listener).to receive(event).with(1, 2, 3, {})
39
+ else
40
+ expect(listener).to receive(event).with(1, 2, 3)
41
+ end
42
+ subject.broadcast(listener, anything, event, *args)
43
+ end
44
+ end
45
+
46
+ context 'with only keyword arguments' do
47
+ let(:kwargs) { { key: 'value' } }
48
+
49
+ it 'sends event to listener with arguments' do
50
+ expect(listener).to receive(event).with({key: 'value'})
51
+ subject.broadcast(listener, anything, event, **kwargs)
52
+ end
53
+ end
54
+
55
+ context 'with positional and keyword arguments' do
56
+ let(:args) { [1,2,3] }
57
+ let(:kwargs) { { key: 'value' } }
19
58
 
20
- it 'sends event to listener with arguments' do
21
- expect(listener).to receive(event).with(*args)
22
- subject.broadcast(listener, anything, event, args)
59
+ it 'sends event to listener with arguments' do
60
+ expect(listener).to receive(event).with(1,2,3, {key: 'value'})
61
+ subject.broadcast(listener, anything, event, *args, **kwargs)
62
+ end
23
63
  end
24
64
  end
25
65
  end
@@ -2,7 +2,7 @@ describe Wisper::ObjectRegistration do
2
2
 
3
3
  describe 'broadcaster' do
4
4
  it 'defaults to SendBroadcaster' do
5
- subject = Wisper::ObjectRegistration.new(double('listener'), {})
5
+ subject = Wisper::ObjectRegistration.new(double('listener'))
6
6
  expect(subject.broadcaster).to be_instance_of(Wisper::Broadcasters::SendBroadcaster)
7
7
  end
8
8
 
data/wisper.gemspec CHANGED
@@ -17,6 +17,8 @@ Gem::Specification.new do |gem|
17
17
  gem.homepage = "https://github.com/krisleech/wisper"
18
18
  gem.license = "MIT"
19
19
 
20
+ gem.required_ruby_version = '>= 2.7'
21
+
20
22
  signing_key = File.expand_path(ENV['HOME'].to_s + '/.ssh/gem-private_key.pem')
21
23
 
22
24
  if File.exist?(signing_key)
@@ -24,8 +26,7 @@ Gem::Specification.new do |gem|
24
26
  gem.cert_chain = ['gem-public_cert.pem']
25
27
  end
26
28
 
27
- gem.files = `git ls-files`.split($/)
28
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
29
+ gem.files = `git ls-files`.split($/).reject { |f| f.split('/').first == 'bin' }
29
30
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
30
31
  gem.require_paths = ["lib"]
31
32
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,35 +1,34 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wisper
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Leech
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDQDCCAiigAwIBAgIBATANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBprcmlz
14
- LmxlZWNoL0RDPWdtYWlsL0RDPWNvbTAeFw0xOTEwMTYxNDEzNDVaFw0yMDEwMTUx
15
- NDEzNDVaMCUxIzAhBgNVBAMMGmtyaXMubGVlY2gvREM9Z21haWwvREM9Y29tMIIB
13
+ MIIC/jCCAeagAwIBAgIBAjANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBprcmlz
14
+ LmxlZWNoL0RDPWdtYWlsL0RDPWNvbTAeFw0yMzA3MDYxNTI0MDdaFw0yNDA3MDUx
15
+ NTI0MDdaMCUxIzAhBgNVBAMMGmtyaXMubGVlY2gvREM9Z21haWwvREM9Y29tMIIB
16
16
  IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8gg/iZE6RFkl6GjisJJf9wQl
17
17
  5Tog+mrGqtylNpe9QKeyQS1fKLNR3Cqmv6sT3f3GlU8hhG+802MXmlJo7VyENs+s
18
18
  HdMy85fBnYwhS/szhTzBqduXw43RAAGqB0VaHAoHdufTZBkmFSXET5c0/jUqQrPL
19
19
  Zxsm2i0NV8cVpvrZlQcsW4Kf97DG1ZFNncS0IfCDqnluh21qMSgVAuiKHGoVKCYG
20
20
  Igey486VuuJ8j6axwW3ii8Ho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TJMgdmlVupROoNjQsJTvuSfUiuy5JFGqS0fijB
28
+ tiGTXMVCk/fOTj04HvFZi/P11KUmQ6HsevziemEgQOnG2lCp+BkyNN0Y4XVW/mno
29
+ x7Y=
31
30
  -----END CERTIFICATE-----
32
- date: 2019-10-16 00:00:00.000000000 Z
31
+ date: 2023-07-06 00:00:00.000000000 Z
33
32
  dependencies: []
34
33
  description: |2
35
34
  A micro library providing objects with Publish-Subscribe capabilities.
@@ -37,22 +36,18 @@ description: |2
37
36
  Check out the Wiki for articles, guides and examples: https://github.com/krisleech/wisper/wiki
38
37
  email:
39
38
  - kris.leech@gmail.com
40
- executables:
41
- - console
42
- - setup
39
+ executables: []
43
40
  extensions: []
44
41
  extra_rdoc_files: []
45
42
  files:
43
+ - ".github/workflows/test.yml"
46
44
  - ".gitignore"
47
45
  - ".rspec"
48
- - ".travis.yml"
49
46
  - CHANGELOG.md
50
47
  - CONTRIBUTING.md
51
48
  - Gemfile
52
49
  - README.md
53
50
  - Rakefile
54
- - bin/console
55
- - bin/setup
56
51
  - gem-public_cert.pem
57
52
  - lib/wisper.rb
58
53
  - lib/wisper/broadcasters/logger_broadcaster.rb
@@ -86,7 +81,7 @@ homepage: https://github.com/krisleech/wisper
86
81
  licenses:
87
82
  - MIT
88
83
  metadata: {}
89
- post_install_message:
84
+ post_install_message:
90
85
  rdoc_options: []
91
86
  require_paths:
92
87
  - lib
@@ -94,15 +89,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
89
  requirements:
95
90
  - - ">="
96
91
  - !ruby/object:Gem::Version
97
- version: '0'
92
+ version: '2.7'
98
93
  required_rubygems_version: !ruby/object:Gem::Requirement
99
94
  requirements:
100
- - - ">="
95
+ - - ">"
101
96
  - !ruby/object:Gem::Version
102
- version: '0'
97
+ version: 1.3.1
103
98
  requirements: []
104
- rubygems_version: 3.0.6
105
- signing_key:
99
+ rubygems_version: 3.3.26
100
+ signing_key:
106
101
  specification_version: 4
107
102
  summary: A micro library providing objects with Publish-Subscribe capabilities
108
103
  test_files:
metadata.gz.sig CHANGED
Binary file
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- language: ruby
2
- before_install:
3
- - gem update --system
4
- - gem update bundler
5
- bundler_args: --without=extras
6
- script: rspec spec
7
- sudo: false
8
- rvm:
9
- - 2.6.3
10
- - 2.5.5
11
- - 2.4.6
12
- - jruby-9.2
13
- # - rbx-2
14
- ### ALLOWED FAILURES ###
15
- # see how compatible we are with dev versions, but do not fail the build
16
- - ruby-head
17
- - jruby-head
18
- matrix:
19
- allow_failures:
20
- - rvm: ruby-head
21
- - rvm: jruby-head
data/bin/console DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "wisper"
5
-
6
- require "pry"
7
- Pry.start
8
-
data/bin/setup DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install