wisper-compat 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/test.yml +19 -0
  3. data/.gitignore +20 -0
  4. data/.rspec +4 -0
  5. data/.ruby-version +1 -0
  6. data/CHANGELOG.md +152 -0
  7. data/CONTRIBUTING.md +57 -0
  8. data/Gemfile +10 -0
  9. data/README.md +358 -0
  10. data/Rakefile +6 -0
  11. data/lib/wisper/broadcasters/logger_broadcaster.rb +41 -0
  12. data/lib/wisper/broadcasters/send_broadcaster.rb +9 -0
  13. data/lib/wisper/configuration.rb +44 -0
  14. data/lib/wisper/global_listeners.rb +72 -0
  15. data/lib/wisper/publisher.rb +89 -0
  16. data/lib/wisper/registration/block.rb +11 -0
  17. data/lib/wisper/registration/object.rb +43 -0
  18. data/lib/wisper/registration/registration.rb +18 -0
  19. data/lib/wisper/temporary_listeners.rb +41 -0
  20. data/lib/wisper/value_objects/events.rb +61 -0
  21. data/lib/wisper/value_objects/prefix.rb +29 -0
  22. data/lib/wisper/version.rb +3 -0
  23. data/lib/wisper.rb +65 -0
  24. data/spec/lib/global_listeners_spec.rb +82 -0
  25. data/spec/lib/integration_spec.rb +56 -0
  26. data/spec/lib/simple_example_spec.rb +21 -0
  27. data/spec/lib/temporary_global_listeners_spec.rb +103 -0
  28. data/spec/lib/wisper/broadcasters/logger_broadcaster_spec.rb +129 -0
  29. data/spec/lib/wisper/broadcasters/send_broadcaster_spec.rb +68 -0
  30. data/spec/lib/wisper/configuration/broadcasters_spec.rb +11 -0
  31. data/spec/lib/wisper/configuration_spec.rb +36 -0
  32. data/spec/lib/wisper/publisher_spec.rb +311 -0
  33. data/spec/lib/wisper/registrations/object_spec.rb +14 -0
  34. data/spec/lib/wisper/value_objects/events_spec.rb +107 -0
  35. data/spec/lib/wisper/value_objects/prefix_spec.rb +46 -0
  36. data/spec/lib/wisper_spec.rb +99 -0
  37. data/spec/spec_helper.rb +21 -0
  38. data/wisper-compat.gemspec +29 -0
  39. metadata +102 -0
@@ -0,0 +1,107 @@
1
+ describe Wisper::ValueObjects::Events do
2
+ context 'nil' do
3
+ subject { described_class.new nil }
4
+
5
+ describe '#include?' do
6
+ it 'returns true' do
7
+ expect(subject.include? 'foo').to be_truthy
8
+ expect(subject.include? :bar).to be_truthy
9
+ end
10
+ end
11
+ end
12
+
13
+ context '"foo"' do
14
+ let(:foo) { Class.new(String).new 'foo' }
15
+ subject { described_class.new foo }
16
+
17
+ describe '#include?' do
18
+ it 'returns true for "foo"' do
19
+ expect(subject.include? 'foo').to be_truthy
20
+ end
21
+
22
+ it 'returns true for :foo' do
23
+ expect(subject.include? :foo).to be_truthy
24
+ end
25
+
26
+ it 'returns false otherwise' do
27
+ expect(subject.include? 'bar').to be_falsey
28
+ expect(subject.include? :bar).to be_falsey
29
+ end
30
+ end
31
+ end
32
+
33
+ context ':foo' do
34
+ subject { described_class.new :foo }
35
+
36
+ describe '#include?' do
37
+ it 'returns true for "foo"' do
38
+ expect(subject.include? 'foo').to be_truthy
39
+ end
40
+
41
+ it 'returns true for :foo' do
42
+ expect(subject.include? :foo).to be_truthy
43
+ end
44
+
45
+ it 'returns false otherwise' do
46
+ expect(subject.include? 'bar').to be_falsey
47
+ expect(subject.include? :bar).to be_falsey
48
+ end
49
+ end
50
+ end
51
+
52
+ context '[:foo, "bar"]' do
53
+ subject { described_class.new [:foo, 'bar'] }
54
+
55
+ describe '#include?' do
56
+ it 'returns true for "foo"' do
57
+ expect(subject.include? 'foo').to be_truthy
58
+ end
59
+
60
+ it 'returns true for :foo' do
61
+ expect(subject.include? :foo).to be_truthy
62
+ end
63
+
64
+ it 'returns true for "bar"' do
65
+ expect(subject.include? 'bar').to be_truthy
66
+ end
67
+
68
+ it 'returns true for :bar' do
69
+ expect(subject.include? :bar).to be_truthy
70
+ end
71
+
72
+ it 'returns false otherwise' do
73
+ expect(subject.include? 'baz').to be_falsey
74
+ expect(subject.include? :baz).to be_falsey
75
+ end
76
+ end
77
+ end
78
+
79
+ context 'by /foo/' do
80
+ subject { described_class.new(/foo/) }
81
+
82
+ describe '#include?' do
83
+ it 'returns true for "foo"' do
84
+ expect(subject.include? 'foo').to be_truthy
85
+ end
86
+
87
+ it 'returns true for :foo' do
88
+ expect(subject.include? :foo).to be_truthy
89
+ end
90
+
91
+ it 'returns false otherwise' do
92
+ expect(subject.include? 'bar').to be_falsey
93
+ expect(subject.include? :bar).to be_falsey
94
+ end
95
+ end
96
+ end
97
+
98
+ context 'another class' do
99
+ subject { described_class.new Object.new }
100
+
101
+ describe '#include?' do
102
+ it 'raises ArgumentError' do
103
+ expect { subject.include? 'foo' }.to raise_error(ArgumentError)
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,46 @@
1
+ describe Wisper::ValueObjects::Prefix do
2
+
3
+ it 'is a string' do
4
+ expect(subject).to be_kind_of String
5
+ end
6
+
7
+ describe '.new' do
8
+ context 'without arguments' do
9
+ subject { described_class.new }
10
+ it { is_expected.to eq '' }
11
+ end
12
+
13
+ context 'nil' do
14
+ subject { described_class.new nil }
15
+ it { is_expected.to eq '' }
16
+ end
17
+
18
+ context 'true' do
19
+ subject { described_class.new true }
20
+ it { is_expected.to eq 'on_' }
21
+ end
22
+
23
+ context '"foo"' do
24
+ subject { described_class.new 'foo' }
25
+ it { is_expected.to eq 'foo_' }
26
+ end
27
+ end
28
+
29
+ describe '.default=' do
30
+ after { described_class.default = nil }
31
+
32
+ context 'nil' do
33
+ it "doesn't change default prefix" do
34
+ expect { described_class.default = nil }
35
+ .not_to change { described_class.new true }.from('on_')
36
+ end
37
+ end
38
+
39
+ context '"foo"' do
40
+ it 'changes default prefix' do
41
+ expect { described_class.default = 'foo' }
42
+ .to change { described_class.new true }.from('on_').to('foo_')
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,99 @@
1
+ describe Wisper do
2
+ describe '.subscribe' do
3
+ context 'when given block' do
4
+
5
+ it 'subscribes listeners to all events for duration of the block' do
6
+ publisher = publisher_class.new
7
+ listener = double('listener')
8
+
9
+ expect(listener).to receive(:first_event)
10
+ expect(listener).not_to receive(:second_event)
11
+
12
+ Wisper.subscribe(listener) do
13
+ publisher.send(:broadcast, 'first_event')
14
+ end
15
+
16
+ publisher.send(:broadcast, 'second_event')
17
+ end
18
+ end
19
+
20
+ context 'when no block given' do
21
+ it 'subscribes listener to all events' do
22
+ listener = double('listener')
23
+ Wisper.subscribe(listener)
24
+ expect(Wisper::GlobalListeners.listeners).to eq [listener]
25
+ end
26
+
27
+ it 'subscribes listeners to all events' do
28
+ listener_1 = double('listener')
29
+ listener_2 = double('listener')
30
+
31
+ Wisper.subscribe(listener_1, listener_2)
32
+
33
+ expect(Wisper::GlobalListeners.listeners).to include listener_1, listener_2
34
+ end
35
+ end
36
+ end
37
+
38
+ describe '.unsubscribe' do
39
+ it 'removes listener from list of listeners' do
40
+ listener = double('listener')
41
+
42
+ Wisper.subscribe(listener)
43
+ expect(Wisper::GlobalListeners.listeners).to eq [listener]
44
+
45
+ Wisper.unsubscribe(listener)
46
+ expect(Wisper::GlobalListeners.listeners).to eq []
47
+ end
48
+
49
+ it 'removes listeners from list of listeners' do
50
+ listener_1 = double('listener')
51
+ listener_2 = double('listener')
52
+
53
+ Wisper.subscribe(listener_1, listener_2)
54
+ expect(Wisper::GlobalListeners.listeners).to include listener_1, listener_2
55
+
56
+ Wisper.unsubscribe(listener_1, listener_2)
57
+ expect(Wisper::GlobalListeners.listeners).to eq []
58
+ end
59
+ end
60
+
61
+ describe '.publisher' do
62
+ it 'returns the Publisher module' do
63
+ expect(Wisper.publisher).to eq Wisper::Publisher
64
+ end
65
+ end
66
+
67
+ describe '.clear' do
68
+ before { Wisper.subscribe(double) }
69
+
70
+ it 'clears all global listeners' do
71
+ Wisper.clear
72
+ expect(Wisper::GlobalListeners.listeners).to be_empty
73
+ end
74
+ end
75
+
76
+ describe '.configuration' do
77
+ it 'returns configuration object' do
78
+ expect(Wisper.configuration).to be_an_instance_of(Wisper::Configuration)
79
+ end
80
+
81
+ it 'is memorized' do
82
+ expect(Wisper.configuration).to eq Wisper.configuration
83
+ end
84
+ end
85
+
86
+ describe '.configure' do
87
+ it 'passes configuration to given block' do
88
+ Wisper.configure do |config|
89
+ expect(config).to be_an_instance_of(Wisper::Configuration)
90
+ end
91
+ end
92
+ end
93
+
94
+ describe '.setup' do
95
+ it 'sets a default broadcaster' do
96
+ expect(Wisper.configuration.broadcasters[:default]).to be_instance_of(Wisper::Broadcasters::SendBroadcaster)
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,21 @@
1
+ require 'wisper'
2
+
3
+ RSpec.configure do |config|
4
+ config.run_all_when_everything_filtered = true
5
+ config.filter_run :focus
6
+ config.order = 'random'
7
+ config.after(:each) { Wisper::GlobalListeners.clear }
8
+
9
+ config.expect_with :rspec do |c|
10
+ c.syntax = :expect
11
+ end
12
+
13
+ config.mock_with :rspec do |c|
14
+ c.syntax = :expect
15
+ end
16
+ end
17
+
18
+ # returns an anonymous wispered class
19
+ def publisher_class
20
+ Class.new { include Wisper::Publisher }
21
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wisper/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "wisper-compat"
8
+ gem.version = Wisper::VERSION
9
+ gem.authors = ["Kris Leech", "Dima Sukhikh", "Jamie Schembri"]
10
+ gem.email = ["kris.leech@gmail.com", "dima.sukhikh@nedap.com", "jamie.schembri@nedap.com"]
11
+ gem.description = <<-DESC
12
+ A micro library providing objects with Publish-Subscribe capabilities.
13
+ Both synchronous (in-process) and asynchronous (out-of-process) subscriptions are supported.
14
+ Check out the Wiki for articles, guides and examples: https://github.com/krisleech/wisper/wiki
15
+ DESC
16
+ gem.summary = "A micro library providing objects with Publish-Subscribe capabilities"
17
+ gem.homepage = "https://github.com/nedap/wisper-compat"
18
+ gem.license = "MIT"
19
+
20
+ gem.required_ruby_version = '>= 2.7'
21
+
22
+ gem.files = `git ls-files`.split($/).reject { |f| f.split('/').first == 'bin' }
23
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
+ gem.require_paths = ["lib"]
25
+
26
+ gem.metadata = {
27
+ "rubygems_mfa_required" => "true"
28
+ }
29
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wisper-compat
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kris Leech
8
+ - Dima Sukhikh
9
+ - Jamie Schembri
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2023-02-28 00:00:00.000000000 Z
14
+ dependencies: []
15
+ description: |2
16
+ A micro library providing objects with Publish-Subscribe capabilities.
17
+ Both synchronous (in-process) and asynchronous (out-of-process) subscriptions are supported.
18
+ Check out the Wiki for articles, guides and examples: https://github.com/krisleech/wisper/wiki
19
+ email:
20
+ - kris.leech@gmail.com
21
+ - dima.sukhikh@nedap.com
22
+ - jamie.schembri@nedap.com
23
+ executables: []
24
+ extensions: []
25
+ extra_rdoc_files: []
26
+ files:
27
+ - ".github/workflows/test.yml"
28
+ - ".gitignore"
29
+ - ".rspec"
30
+ - ".ruby-version"
31
+ - CHANGELOG.md
32
+ - CONTRIBUTING.md
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - lib/wisper.rb
37
+ - lib/wisper/broadcasters/logger_broadcaster.rb
38
+ - lib/wisper/broadcasters/send_broadcaster.rb
39
+ - lib/wisper/configuration.rb
40
+ - lib/wisper/global_listeners.rb
41
+ - lib/wisper/publisher.rb
42
+ - lib/wisper/registration/block.rb
43
+ - lib/wisper/registration/object.rb
44
+ - lib/wisper/registration/registration.rb
45
+ - lib/wisper/temporary_listeners.rb
46
+ - lib/wisper/value_objects/events.rb
47
+ - lib/wisper/value_objects/prefix.rb
48
+ - lib/wisper/version.rb
49
+ - spec/lib/global_listeners_spec.rb
50
+ - spec/lib/integration_spec.rb
51
+ - spec/lib/simple_example_spec.rb
52
+ - spec/lib/temporary_global_listeners_spec.rb
53
+ - spec/lib/wisper/broadcasters/logger_broadcaster_spec.rb
54
+ - spec/lib/wisper/broadcasters/send_broadcaster_spec.rb
55
+ - spec/lib/wisper/configuration/broadcasters_spec.rb
56
+ - spec/lib/wisper/configuration_spec.rb
57
+ - spec/lib/wisper/publisher_spec.rb
58
+ - spec/lib/wisper/registrations/object_spec.rb
59
+ - spec/lib/wisper/value_objects/events_spec.rb
60
+ - spec/lib/wisper/value_objects/prefix_spec.rb
61
+ - spec/lib/wisper_spec.rb
62
+ - spec/spec_helper.rb
63
+ - wisper-compat.gemspec
64
+ homepage: https://github.com/nedap/wisper-compat
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ rubygems_mfa_required: 'true'
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '2.7'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubygems_version: 3.4.6
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: A micro library providing objects with Publish-Subscribe capabilities
88
+ test_files:
89
+ - spec/lib/global_listeners_spec.rb
90
+ - spec/lib/integration_spec.rb
91
+ - spec/lib/simple_example_spec.rb
92
+ - spec/lib/temporary_global_listeners_spec.rb
93
+ - spec/lib/wisper/broadcasters/logger_broadcaster_spec.rb
94
+ - spec/lib/wisper/broadcasters/send_broadcaster_spec.rb
95
+ - spec/lib/wisper/configuration/broadcasters_spec.rb
96
+ - spec/lib/wisper/configuration_spec.rb
97
+ - spec/lib/wisper/publisher_spec.rb
98
+ - spec/lib/wisper/registrations/object_spec.rb
99
+ - spec/lib/wisper/value_objects/events_spec.rb
100
+ - spec/lib/wisper/value_objects/prefix_spec.rb
101
+ - spec/lib/wisper_spec.rb
102
+ - spec/spec_helper.rb