dry-events 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -5
- data/LICENSE +1 -1
- data/README.md +4 -12
- data/dry-events.gemspec +8 -11
- data/lib/dry/events/bus.rb +5 -3
- data/lib/dry/events/constants.rb +2 -2
- data/lib/dry/events/event.rb +3 -3
- data/lib/dry/events/filter.rb +5 -5
- data/lib/dry/events/listener.rb +1 -1
- data/lib/dry/events/publisher.rb +11 -11
- data/lib/dry/events/version.rb +1 -1
- metadata +10 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b060fcc9482241a19cd23e817717d3702d5e075a1df70358a212d9865d79dde8
|
4
|
+
data.tar.gz: c3d87474731b5cce582f5d337725a0bcdd56711c2d8571d8038302b813d051fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 904216a0c90b2a6108c2743a681855d46d64d6b419bda61b84d19d4721081f88f1bd5aa2d5e209383b47178d2682884ce69f72a3b3819782929d52ab5e887166
|
7
|
+
data.tar.gz: 53f854b310a1b69acb9562c93e35e06f2a8be370c6a9cfbe49095268ec544638df4397b974d3e5232f2ffcf7fc3fefd7d810b1a361d3d4fe5dae9958b29375da
|
data/CHANGELOG.md
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
-
## 1.
|
3
|
+
## 1.1.0 2025-01-04
|
4
4
|
|
5
5
|
|
6
6
|
### Fixed
|
7
7
|
|
8
|
-
-
|
8
|
+
- Calling `Publisher#unsubscribe` when there's a block subscription now works (via #17) (@Aerdayne)
|
9
9
|
|
10
10
|
### Changed
|
11
11
|
|
12
|
-
-
|
13
|
-
|
12
|
+
- Set minimum Ruby version to 3.1.0 (@flash-gordon)
|
13
|
+
|
14
|
+
[Compare v1.0.1...v1.1.0](https://github.com/dry-rb/dry-events/compare/v1.0.1...v1.1.0)
|
15
|
+
|
16
|
+
## 1.0.1 2022-11-20
|
17
|
+
|
18
|
+
|
19
|
+
### Fixed
|
20
|
+
|
21
|
+
- Make listeners hash thread-safe (via #16) (@mensfeld)
|
22
|
+
|
14
23
|
|
15
|
-
[Compare v1.0.0...v1.0.
|
24
|
+
[Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-events/compare/v1.0.0...v1.0.1)
|
16
25
|
|
17
26
|
## 1.0.0 2022-11-04
|
18
27
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,21 @@
|
|
1
1
|
<!--- this file is synced from dry-rb/template-gem project -->
|
2
2
|
[gem]: https://rubygems.org/gems/dry-events
|
3
3
|
[actions]: https://github.com/dry-rb/dry-events/actions
|
4
|
-
[codacy]: https://www.codacy.com/gh/dry-rb/dry-events
|
5
|
-
[chat]: https://dry-rb.zulipchat.com
|
6
|
-
[inchpages]: http://inch-ci.org/github/dry-rb/dry-events
|
7
4
|
|
8
|
-
# dry-events [![
|
9
|
-
|
10
|
-
[![Gem Version](https://badge.fury.io/rb/dry-events.svg)][gem]
|
11
|
-
[![CI Status](https://github.com/dry-rb/dry-events/workflows/ci/badge.svg)][actions]
|
12
|
-
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/3170162485134ea3b778c7e20e180b26)][codacy]
|
13
|
-
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/3170162485134ea3b778c7e20e180b26)][codacy]
|
14
|
-
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-events.svg?branch=main)][inchpages]
|
5
|
+
# dry-events [![Gem Version](https://badge.fury.io/rb/dry-events.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-events/workflows/ci/badge.svg)][actions]
|
15
6
|
|
16
7
|
## Links
|
17
8
|
|
18
9
|
* [User documentation](https://dry-rb.org/gems/dry-events)
|
19
10
|
* [API documentation](http://rubydoc.info/gems/dry-events)
|
11
|
+
* [Forum](https://discourse.dry-rb.org)
|
20
12
|
|
21
13
|
## Supported Ruby versions
|
22
14
|
|
23
15
|
This library officially supports the following Ruby versions:
|
24
16
|
|
25
|
-
* MRI `>=
|
26
|
-
* jruby `>= 9.
|
17
|
+
* MRI `>= 3.0.0`
|
18
|
+
* jruby `>= 9.4` (not tested on CI)
|
27
19
|
|
28
20
|
## License
|
29
21
|
|
data/dry-events.gemspec
CHANGED
@@ -21,18 +21,15 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = []
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.metadata["allowed_push_host"]
|
25
|
-
spec.metadata["changelog_uri"]
|
26
|
-
spec.metadata["source_code_uri"]
|
27
|
-
spec.metadata["bug_tracker_uri"]
|
24
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
25
|
+
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-events/blob/main/CHANGELOG.md"
|
26
|
+
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-events"
|
27
|
+
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-events/issues"
|
28
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
28
29
|
|
29
|
-
spec.required_ruby_version = ">=
|
30
|
+
spec.required_ruby_version = ">= 3.1.0"
|
30
31
|
|
31
32
|
# to update dependencies edit project.yml
|
32
|
-
spec.
|
33
|
-
spec.
|
34
|
-
|
35
|
-
spec.add_development_dependency "bundler"
|
36
|
-
spec.add_development_dependency "rake"
|
37
|
-
spec.add_development_dependency "rspec"
|
33
|
+
spec.add_dependency "concurrent-ruby", "~> 1.0"
|
34
|
+
spec.add_dependency "dry-core", "~> 1.1"
|
38
35
|
end
|
data/lib/dry/events/bus.rb
CHANGED
@@ -63,6 +63,8 @@ module Dry
|
|
63
63
|
listeners.each do |id, memo|
|
64
64
|
memo.each do |tuple|
|
65
65
|
current_listener, _ = tuple
|
66
|
+
next unless current_listener.is_a?(Method)
|
67
|
+
|
66
68
|
listeners[id].delete(tuple) if current_listener.receiver.equal?(listener)
|
67
69
|
end
|
68
70
|
end
|
@@ -79,8 +81,8 @@ module Dry
|
|
79
81
|
listeners.values.any? do |value|
|
80
82
|
value.any? do |block, _|
|
81
83
|
case listener
|
82
|
-
when Proc then block.equal?(listener)
|
83
|
-
when Method then listener.owner == block.owner && listener.name == block.name
|
84
|
+
when ::Proc then block.equal?(listener)
|
85
|
+
when ::Method then listener.owner == block.owner && listener.name == block.name
|
84
86
|
end
|
85
87
|
end
|
86
88
|
end
|
@@ -89,7 +91,7 @@ module Dry
|
|
89
91
|
# @api private
|
90
92
|
def can_handle?(object_or_event_id)
|
91
93
|
case object_or_event_id
|
92
|
-
when String, Symbol
|
94
|
+
when ::String, ::Symbol
|
93
95
|
events.key?(object_or_event_id)
|
94
96
|
else
|
95
97
|
events
|
data/lib/dry/events/constants.rb
CHANGED
@@ -4,9 +4,9 @@ require "concurrent/map"
|
|
4
4
|
|
5
5
|
module Dry
|
6
6
|
module Events
|
7
|
-
include Dry::Core::Constants
|
7
|
+
include ::Dry::Core::Constants
|
8
8
|
|
9
|
-
LISTENERS_HASH = Concurrent::Map.new do |h, k|
|
9
|
+
LISTENERS_HASH = ::Concurrent::Map.new do |h, k|
|
10
10
|
h.compute_if_absent(k) { [] }
|
11
11
|
end
|
12
12
|
end
|
data/lib/dry/events/event.rb
CHANGED
@@ -8,9 +8,9 @@ module Dry
|
|
8
8
|
#
|
9
9
|
# @api public
|
10
10
|
class Event
|
11
|
-
include Dry::Equalizer(:id, :payload)
|
11
|
+
include ::Dry::Equalizer(:id, :payload)
|
12
12
|
|
13
|
-
InvalidEventNameError = Class.new(StandardError) do
|
13
|
+
InvalidEventNameError = ::Class.new(::StandardError) do
|
14
14
|
# @api private
|
15
15
|
def initialize
|
16
16
|
super("please provide a valid event name, it could be either String or Symbol")
|
@@ -26,7 +26,7 @@ module Dry
|
|
26
26
|
|
27
27
|
# @api private
|
28
28
|
def self.new(id, payload = EMPTY_HASH)
|
29
|
-
return super
|
29
|
+
return super if (id.is_a?(::String) || id.is_a?(::Symbol)) && !id.empty?
|
30
30
|
|
31
31
|
raise InvalidEventNameError
|
32
32
|
end
|
data/lib/dry/events/filter.rb
CHANGED
@@ -11,7 +11,7 @@ module Dry
|
|
11
11
|
#
|
12
12
|
# @api private
|
13
13
|
class Filter
|
14
|
-
NO_MATCH = Object.new.freeze
|
14
|
+
NO_MATCH = ::Object.new.freeze
|
15
15
|
|
16
16
|
# @!attribute [r] events
|
17
17
|
# @return [Array] A list of lambdas checking payloads
|
@@ -39,7 +39,7 @@ module Dry
|
|
39
39
|
#
|
40
40
|
# @api private
|
41
41
|
def build_checks(filter, checks = EMPTY_ARRAY, keys = EMPTY_ARRAY)
|
42
|
-
if filter.is_a?(Hash)
|
42
|
+
if filter.is_a?(::Hash)
|
43
43
|
filter.reduce(checks) do |cs, (key, value)|
|
44
44
|
build_checks(value, cs, [*keys, key])
|
45
45
|
end
|
@@ -51,7 +51,7 @@ module Dry
|
|
51
51
|
# @api private
|
52
52
|
def compare(path, predicate, payload)
|
53
53
|
value = path.reduce(payload) do |acc, key|
|
54
|
-
if acc.is_a?(Hash) && acc.key?(key)
|
54
|
+
if acc.is_a?(::Hash) && acc.key?(key)
|
55
55
|
acc[key]
|
56
56
|
else
|
57
57
|
break NO_MATCH
|
@@ -64,8 +64,8 @@ module Dry
|
|
64
64
|
# @api private
|
65
65
|
def predicate(value)
|
66
66
|
case value
|
67
|
-
when Proc then value
|
68
|
-
when Array then value.method(:include?)
|
67
|
+
when ::Proc then value
|
68
|
+
when ::Array then value.method(:include?)
|
69
69
|
else value.method(:==)
|
70
70
|
end
|
71
71
|
end
|
data/lib/dry/events/listener.rb
CHANGED
data/lib/dry/events/publisher.rb
CHANGED
@@ -11,7 +11,7 @@ module Dry
|
|
11
11
|
# Exception raised when the same publisher is registered more than once
|
12
12
|
#
|
13
13
|
# @api public
|
14
|
-
PublisherAlreadyRegisteredError = Class.new(StandardError) do
|
14
|
+
PublisherAlreadyRegisteredError = ::Class.new(::StandardError) do
|
15
15
|
# @api private
|
16
16
|
def initialize(id)
|
17
17
|
super("publisher with id #{id.inspect} already registered as: #{Publisher.registry[id]}")
|
@@ -19,13 +19,13 @@ module Dry
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# @api public
|
22
|
-
InvalidSubscriberError = Class.new(StandardError) do
|
22
|
+
InvalidSubscriberError = ::Class.new(::StandardError) do
|
23
23
|
# @api private
|
24
24
|
def initialize(object_or_event_id)
|
25
25
|
case object_or_event_id
|
26
|
-
when String, Symbol
|
26
|
+
when ::String, ::Symbol
|
27
27
|
super(
|
28
|
-
"you are trying to subscribe to an event: `#{object_or_event_id}` "\
|
28
|
+
"you are trying to subscribe to an event: `#{object_or_event_id}` " \
|
29
29
|
"that has not been registered"
|
30
30
|
)
|
31
31
|
else
|
@@ -34,10 +34,10 @@ module Dry
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
UnregisteredEventError = Class.new(StandardError) do
|
37
|
+
UnregisteredEventError = ::Class.new(::StandardError) do
|
38
38
|
def initialize(object_or_event_id)
|
39
39
|
case object_or_event_id
|
40
|
-
when String, Symbol
|
40
|
+
when ::String, ::Symbol
|
41
41
|
super("You are trying to publish an unregistered event: `#{object_or_event_id}`")
|
42
42
|
else
|
43
43
|
super("You are trying to publish an unregistered event")
|
@@ -75,7 +75,7 @@ module Dry
|
|
75
75
|
#
|
76
76
|
# @api public
|
77
77
|
class Publisher < ::Module
|
78
|
-
include Dry::Equalizer(:id)
|
78
|
+
include ::Dry::Equalizer(:id)
|
79
79
|
|
80
80
|
# Internal publisher registry, which is used to identify them globally
|
81
81
|
#
|
@@ -84,7 +84,7 @@ module Dry
|
|
84
84
|
#
|
85
85
|
# @api private
|
86
86
|
def self.registry
|
87
|
-
@__registry__ ||= Concurrent::Map.new
|
87
|
+
@__registry__ ||= ::Concurrent::Map.new
|
88
88
|
end
|
89
89
|
|
90
90
|
# @!attribute [r] :id
|
@@ -168,7 +168,7 @@ module Dry
|
|
168
168
|
#
|
169
169
|
# @api private
|
170
170
|
def events
|
171
|
-
@__events__ ||= Concurrent::Map.new
|
171
|
+
@__events__ ||= ::Concurrent::Map.new
|
172
172
|
end
|
173
173
|
|
174
174
|
# Global registry with listeners
|
@@ -265,8 +265,8 @@ module Dry
|
|
265
265
|
# param [Hash] payload An optional payload
|
266
266
|
#
|
267
267
|
# @api public
|
268
|
-
def process(event_id, payload = EMPTY_HASH, &
|
269
|
-
__bus__.process(event_id, payload, &
|
268
|
+
def process(event_id, payload = EMPTY_HASH, &)
|
269
|
+
__bus__.process(event_id, payload, &)
|
270
270
|
end
|
271
271
|
|
272
272
|
# Internal event bus
|
data/lib/dry/events/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-events
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -30,62 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
34
|
-
- - "<"
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: '2'
|
33
|
+
version: '1.1'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
38
|
- - "~>"
|
42
39
|
- !ruby/object:Gem::Version
|
43
|
-
version: '1.
|
44
|
-
- - "<"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '2'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: bundler
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '0'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: rake
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '0'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: rspec
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '0'
|
82
|
-
type: :development
|
83
|
-
prerelease: false
|
84
|
-
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '0'
|
40
|
+
version: '1.1'
|
89
41
|
description: Pub/sub system
|
90
42
|
email:
|
91
43
|
- piotr.solnica+oss@gmail.com
|
@@ -114,7 +66,8 @@ metadata:
|
|
114
66
|
changelog_uri: https://github.com/dry-rb/dry-events/blob/main/CHANGELOG.md
|
115
67
|
source_code_uri: https://github.com/dry-rb/dry-events
|
116
68
|
bug_tracker_uri: https://github.com/dry-rb/dry-events/issues
|
117
|
-
|
69
|
+
rubygems_mfa_required: 'true'
|
70
|
+
post_install_message:
|
118
71
|
rdoc_options: []
|
119
72
|
require_paths:
|
120
73
|
- lib
|
@@ -122,15 +75,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
75
|
requirements:
|
123
76
|
- - ">="
|
124
77
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
78
|
+
version: 3.1.0
|
126
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
80
|
requirements:
|
128
81
|
- - ">="
|
129
82
|
- !ruby/object:Gem::Version
|
130
83
|
version: '0'
|
131
84
|
requirements: []
|
132
|
-
rubygems_version: 3.
|
133
|
-
signing_key:
|
85
|
+
rubygems_version: 3.3.27
|
86
|
+
signing_key:
|
134
87
|
specification_version: 4
|
135
88
|
summary: Pub/sub system
|
136
89
|
test_files: []
|