reactor 0.11.2 → 0.11.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changes.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/reactor/models/concerns/subscribable.rb +19 -4
- data/lib/reactor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f2967da3845ee85524fe9c738839f0e6fdb29c7
|
4
|
+
data.tar.gz: c0ed7956ea7c152528db44ec1c898c47415d1cb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a155ca4b6daf0250992a8e3a9a15f8b5a56ccab20a5e8c04ee80e26e19b234a4a9e486e5f6932bbb76226a7d3d3570235402a9eb9873175b0f4c398dc6788be7
|
7
|
+
data.tar.gz: 106ba452f9d9a2b2623157738f271f20afee7a6df280e4f9971a071ff572361e60fae79e414329076a0d4233bce55b8a9e9f2c77b21057f916be4f473ed9ab60
|
data/Changes.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -4,18 +4,25 @@ module Reactor::Subscribable
|
|
4
4
|
class EventHandlerAlreadyDefined < StandardError ; end
|
5
5
|
|
6
6
|
module ClassMethods
|
7
|
+
|
7
8
|
def on_event(*args, &block)
|
8
9
|
options = args.extract_options!
|
9
10
|
event, method = args
|
10
|
-
|
11
|
+
if subscriber = create_static_subscriber(event, method, options, &block)
|
12
|
+
(Reactor::SUBSCRIBERS[event.to_s] ||= []).push(subscriber)
|
13
|
+
end
|
11
14
|
end
|
12
15
|
|
13
16
|
private
|
14
17
|
|
15
18
|
def create_static_subscriber(event, method = nil, options = {}, &block)
|
16
19
|
worker_class = build_worker_class
|
20
|
+
handler_name = handler_name(event, options[:handler_name])
|
21
|
+
check_for_duplicate_handler_name(handler_name)
|
17
22
|
|
18
|
-
|
23
|
+
# return if the handler has already been defined (in the case of the class being reloaded)
|
24
|
+
return if static_subscriber_namespace.const_defined?(handler_name)
|
25
|
+
name_worker_class worker_class, handler_name
|
19
26
|
|
20
27
|
worker_class.tap do |k|
|
21
28
|
k.source = self
|
@@ -31,6 +38,10 @@ module Reactor::Subscribable
|
|
31
38
|
"#{event == '*' ? 'Wildcard': event.to_s.camelize}Handler"
|
32
39
|
end
|
33
40
|
|
41
|
+
def event_handler_names
|
42
|
+
@event_handler_names ||= []
|
43
|
+
end
|
44
|
+
|
34
45
|
def build_worker_class
|
35
46
|
Class.new do
|
36
47
|
include Sidekiq::Worker
|
@@ -57,13 +68,17 @@ module Reactor::Subscribable
|
|
57
68
|
end
|
58
69
|
end
|
59
70
|
|
60
|
-
def
|
61
|
-
if
|
71
|
+
def check_for_duplicate_handler_name(handler_name)
|
72
|
+
if event_handler_names.include?(handler_name)
|
62
73
|
raise EventHandlerAlreadyDefined.new(
|
63
74
|
"A Reactor event named #{handler_name} already has been defined on #{static_subscriber_namespace}.
|
64
75
|
Specify a `:handler_name` option on your subscriber's `on_event` declaration to name this event handler deterministically."
|
65
76
|
)
|
66
77
|
end
|
78
|
+
event_handler_names << handler_name
|
79
|
+
end
|
80
|
+
|
81
|
+
def name_worker_class(klass, handler_name)
|
67
82
|
static_subscriber_namespace.const_set(handler_name, klass)
|
68
83
|
end
|
69
84
|
|
data/lib/reactor/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winfred
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-03-
|
14
|
+
date: 2016-03-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: sidekiq
|