evil_events 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hound.yml +2 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +3 -2
- data/CHANGELOG.md +18 -0
- data/evil_events.gemspec +3 -3
- data/lib/evil_events/application.rb +7 -0
- data/lib/evil_events/core/broadcasting/emitter.rb +5 -7
- data/lib/evil_events/core/config.rb +16 -1
- data/lib/evil_events/core/events/abstract_event.rb +2 -0
- data/lib/evil_events/core/events/event_extensions/class_signature/signature.rb +1 -1
- data/lib/evil_events/core/events/event_extensions/class_signature.rb +1 -1
- data/lib/evil_events/core/events/event_extensions/emittable.rb +29 -0
- data/lib/evil_events/core/events/event_extensions/hookable/abstract_hook.rb +27 -0
- data/lib/evil_events/core/events/event_extensions/hookable/after_emit_hook.rb +11 -0
- data/lib/evil_events/core/events/event_extensions/hookable/before_emit_hook.rb +11 -0
- data/lib/evil_events/core/events/event_extensions/hookable/on_error_hook.rb +16 -0
- data/lib/evil_events/core/events/event_extensions/hookable.rb +93 -0
- data/lib/evil_events/core/events/event_extensions/type_aliasing.rb +6 -12
- data/lib/evil_events/core/events/event_factory.rb +4 -4
- data/lib/evil_events/core/events/manager.rb +14 -12
- data/lib/evil_events/core/events/manager_factory.rb +2 -7
- data/lib/evil_events/core/events/manager_registry.rb +8 -15
- data/lib/evil_events/core/events/notifier/abstract.rb +26 -0
- data/lib/evil_events/core/events/notifier/builder.rb +43 -0
- data/lib/evil_events/core/events/notifier/logging.rb +43 -0
- data/lib/evil_events/core/events/notifier/proxy.rb +33 -0
- data/lib/evil_events/core/events/notifier/sequential.rb +41 -0
- data/lib/evil_events/core/events/notifier/worker/executor.rb +102 -0
- data/lib/evil_events/core/events/notifier/worker/job.rb +35 -0
- data/lib/evil_events/core/events/notifier/worker.rb +71 -0
- data/lib/evil_events/core/events/notifier.rb +6 -0
- data/lib/evil_events/core/events/serializers/hash.rb +9 -7
- data/lib/evil_events/core/events/serializers/json.rb +11 -6
- data/lib/evil_events/core/events/serializers.rb +0 -7
- data/lib/evil_events/core/events/subscriber/mixin.rb +2 -2
- data/lib/evil_events/core/events.rb +14 -1
- data/lib/evil_events/core/system/broadcaster.rb +23 -1
- data/lib/evil_events/core/system/mock.rb +7 -0
- data/lib/evil_events/core/system.rb +3 -1
- data/lib/evil_events/core.rb +0 -1
- data/lib/evil_events/error.rb +96 -0
- data/lib/evil_events/plugins/{rails.rb → redis_adapter.rb} +2 -2
- data/lib/evil_events/plugins/{elastic_search.rb → sidekiq_adapter.rb} +2 -2
- data/lib/evil_events/plugins.rb +15 -13
- data/lib/evil_events/shared/extensions_mixin.rb +7 -0
- data/lib/evil_events/shared/type_converter/converter_registry.rb +2 -2
- data/lib/evil_events/shared.rb +1 -0
- data/lib/evil_events/version.rb +1 -1
- data/lib/evil_events.rb +1 -0
- metadata +27 -12
- data/lib/evil_events/core/error.rb +0 -8
- data/lib/evil_events/core/events/manager/notifier.rb +0 -79
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EvilEvents
|
4
|
+
# @since 0.3.0
|
5
|
+
Error = Class.new(StandardError)
|
6
|
+
# @since 0.3.0
|
7
|
+
ArgumentError = Class.new(ArgumentError)
|
8
|
+
|
9
|
+
# NOTE: see EvilEvents::Core::Broadcasting::Emitter
|
10
|
+
# @since 0.3.0
|
11
|
+
EmitterError = Class.new(Error)
|
12
|
+
# since 0.3.0
|
13
|
+
IncorrectEventForEmitError = Class.new(EmitterError)
|
14
|
+
|
15
|
+
# NOTE: see EvilEvents::Core::Events::EventExtensions::TypeAliasing
|
16
|
+
# @since 0.3.0
|
17
|
+
TypeAliasingError = Class.new(Error)
|
18
|
+
# @since 0.3.0
|
19
|
+
IncopatibleEventTypeError = Class.new(TypeAliasingError)
|
20
|
+
# @since 0.3.0
|
21
|
+
EventTypeNotDefinedError = Class.new(TypeAliasingError)
|
22
|
+
# @since 0.3.0
|
23
|
+
EventTypeAlreadyDefinedError = Class.new(TypeAliasingError)
|
24
|
+
|
25
|
+
# NOTE: see EvilEvents::Core::Events::Notifier::Builder
|
26
|
+
# @since 0.3.0
|
27
|
+
NotifierBuilderError = Class.new(Error)
|
28
|
+
# @since 0.3.0
|
29
|
+
UnknownNotifierTypeError = Class.new(NotifierBuilderError)
|
30
|
+
|
31
|
+
# NOTE: see EvilEvents::Core::Events::Manager
|
32
|
+
# @since 0.3.0
|
33
|
+
ManagerError = Class.new(Error)
|
34
|
+
# @since 0.3.0
|
35
|
+
InconsistentEventClassError = Class.new(ManagerError)
|
36
|
+
# @since 0.3.0
|
37
|
+
InvalidDelegatorTypeError = Class.new(ManagerError)
|
38
|
+
|
39
|
+
# NOTE: see EvilEvents::Core::Events::ManagerFactory
|
40
|
+
# @since 0.3.0
|
41
|
+
ManagerFactoryError = Class.new(Error)
|
42
|
+
# @since 0.3.0
|
43
|
+
IncorrectEventClassError = Class.new(ManagerFactoryError)
|
44
|
+
|
45
|
+
# NOTE: see EvilEvents::Core::Events::ManagerRegistry
|
46
|
+
# @since 0.3.0
|
47
|
+
ManagerRegistryError = Class.new(Error)
|
48
|
+
# @since 0.3.0
|
49
|
+
IncorrectManagerObjectError = Class.new(ManagerRegistryError)
|
50
|
+
# @since 0.3.0
|
51
|
+
NonManagedEventClassError = Class.new(ManagerRegistryError)
|
52
|
+
# @since 0.3.0
|
53
|
+
AlreadyManagedEventClassError = Class.new(ManagerRegistryError)
|
54
|
+
|
55
|
+
# NOTE: EvilEvents::Core::Events::Serializers
|
56
|
+
# @since 0.3.0
|
57
|
+
SerializersError = Class.new(Error)
|
58
|
+
# @since 0.3.0
|
59
|
+
SerializationError = Class.new(SerializersError)
|
60
|
+
# @since 0.3.0
|
61
|
+
DeserializationError = Class.new(SerializersError)
|
62
|
+
|
63
|
+
# NOTE: see EvilEvents::Core::Events::Notifier
|
64
|
+
# @since 0.3.0
|
65
|
+
NotifierError = Class.new(Error)
|
66
|
+
# @since 0.3.0
|
67
|
+
class FailedNotifiedSubscribersError < NotifierError
|
68
|
+
# @since 0.3.0
|
69
|
+
extend Forwardable
|
70
|
+
|
71
|
+
# @since 0.3.0
|
72
|
+
def_delegators :errors_stack, :<<, :empty?
|
73
|
+
|
74
|
+
# @return [Concurrent::Array]
|
75
|
+
#
|
76
|
+
# @api public
|
77
|
+
# @since 0.3.0
|
78
|
+
attr_reader :errors_stack
|
79
|
+
|
80
|
+
# @param message [NilClass, String]
|
81
|
+
#
|
82
|
+
# @since 0.3.0
|
83
|
+
def initialize(message = nil)
|
84
|
+
@errors_stack = Concurrent::Array.new
|
85
|
+
super
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# NOTE: see EvilEvents::Core::Events::Notifier::Worker::Executor
|
90
|
+
# @since 0.3.0
|
91
|
+
WorkerError = Class.new(NotifierError)
|
92
|
+
# @since 0.3.0
|
93
|
+
IncorrectFallbackPolicyError = Class.new(WorkerError)
|
94
|
+
# @since 0.3.0
|
95
|
+
WorkerDisabledOrBusyError = Class.new(WorkerError)
|
96
|
+
end
|
data/lib/evil_events/plugins.rb
CHANGED
@@ -4,29 +4,31 @@ module EvilEvents
|
|
4
4
|
# @api public
|
5
5
|
# @since 0.2.0
|
6
6
|
class Plugins
|
7
|
-
# @since 0.
|
8
|
-
extend Shared::
|
7
|
+
# @since 0.3.0
|
8
|
+
extend Shared::ExtensionsMixin
|
9
9
|
|
10
|
-
# @since 0.
|
11
|
-
|
12
|
-
# @since 0.
|
13
|
-
|
10
|
+
# @since 0.3.0
|
11
|
+
register_extension(:redis_adapter) { require_relative 'plugins/redis_adapter' }
|
12
|
+
# @since 0.3.0
|
13
|
+
register_extension(:sidekiq_adapter) { require_relative 'plugins/sidekiq_adapter' }
|
14
14
|
|
15
15
|
class << self
|
16
|
-
# @
|
16
|
+
# @param plugins [Symbol,Symbol,Symbol,...]
|
17
|
+
# @raise [ArgumentError] When required plugin is not registered
|
18
|
+
# @return void
|
17
19
|
#
|
20
|
+
# @api public
|
18
21
|
# @since 0.2.0
|
19
|
-
def
|
20
|
-
|
22
|
+
def load!(*plugins)
|
23
|
+
load_extensions(*(plugins.empty? ? names : plugins))
|
21
24
|
end
|
22
25
|
|
23
|
-
# @
|
24
|
-
# @return void
|
26
|
+
# @return [Array<Symbol>]
|
25
27
|
#
|
26
28
|
# @api public
|
27
29
|
# @since 0.2.0
|
28
|
-
def
|
29
|
-
|
30
|
+
def names
|
31
|
+
@__available_extensions__.keys
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -23,7 +23,7 @@ class EvilEvents::Shared::TypeConverter
|
|
23
23
|
|
24
24
|
# @param type_name [Symbol]
|
25
25
|
# @param coercer [Proc]
|
26
|
-
# @raise ArgumentError
|
26
|
+
# @raise [ArgumentError]
|
27
27
|
# @return [Converter]
|
28
28
|
#
|
29
29
|
# @api public
|
@@ -38,7 +38,7 @@ class EvilEvents::Shared::TypeConverter
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# @param type [Mixed]
|
41
|
-
# @raise ConverterNotRegisteredError
|
41
|
+
# @raise [ConverterNotRegisteredError]
|
42
42
|
# @return [Mixed]
|
43
43
|
#
|
44
44
|
# @api public
|
data/lib/evil_events/shared.rb
CHANGED
@@ -13,6 +13,7 @@ module EvilEvents
|
|
13
13
|
require_relative 'shared/combined_context/mixin'
|
14
14
|
require_relative 'shared/delegator_resolver'
|
15
15
|
require_relative 'shared/dependency_container'
|
16
|
+
require_relative 'shared/extensions_mixin'
|
16
17
|
require_relative 'shared/clonable_module_builder'
|
17
18
|
require_relative 'shared/type_converter'
|
18
19
|
require_relative 'shared/type_converter/converter'
|
data/lib/evil_events/version.rb
CHANGED
data/lib/evil_events.rb
CHANGED
@@ -16,6 +16,7 @@ module EvilEvents
|
|
16
16
|
require_relative 'evil_events/version'
|
17
17
|
require_relative 'evil_events/shared'
|
18
18
|
require_relative 'evil_events/types'
|
19
|
+
require_relative 'evil_events/error'
|
19
20
|
require_relative 'evil_events/core'
|
20
21
|
require_relative 'evil_events/config'
|
21
22
|
require_relative 'evil_events/event'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evil_events
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rustam Ibragimov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-monads
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.12.
|
33
|
+
version: 0.12.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.12.
|
40
|
+
version: 0.12.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: dry-struct
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.
|
145
|
+
version: 0.52.1
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.
|
152
|
+
version: 0.52.1
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rspec
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,14 +170,14 @@ dependencies:
|
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: 1.
|
173
|
+
version: 1.23.0
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: 1.
|
180
|
+
version: 1.23.0
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: pry
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -229,6 +229,7 @@ extensions: []
|
|
229
229
|
extra_rdoc_files: []
|
230
230
|
files:
|
231
231
|
- ".gitignore"
|
232
|
+
- ".hound.yml"
|
232
233
|
- ".jrubyrc"
|
233
234
|
- ".rspec"
|
234
235
|
- ".rubocop.yml"
|
@@ -258,7 +259,6 @@ files:
|
|
258
259
|
- lib/evil_events/core/broadcasting/dispatcher/mixin.rb
|
259
260
|
- lib/evil_events/core/broadcasting/emitter.rb
|
260
261
|
- lib/evil_events/core/config.rb
|
261
|
-
- lib/evil_events/core/error.rb
|
262
262
|
- lib/evil_events/core/events.rb
|
263
263
|
- lib/evil_events/core/events/abstract_event.rb
|
264
264
|
- lib/evil_events/core/events/event_extensions/adapter_customizable.rb
|
@@ -266,6 +266,11 @@ files:
|
|
266
266
|
- lib/evil_events/core/events/event_extensions/class_signature/equalizer.rb
|
267
267
|
- lib/evil_events/core/events/event_extensions/class_signature/signature.rb
|
268
268
|
- lib/evil_events/core/events/event_extensions/emittable.rb
|
269
|
+
- lib/evil_events/core/events/event_extensions/hookable.rb
|
270
|
+
- lib/evil_events/core/events/event_extensions/hookable/abstract_hook.rb
|
271
|
+
- lib/evil_events/core/events/event_extensions/hookable/after_emit_hook.rb
|
272
|
+
- lib/evil_events/core/events/event_extensions/hookable/before_emit_hook.rb
|
273
|
+
- lib/evil_events/core/events/event_extensions/hookable/on_error_hook.rb
|
269
274
|
- lib/evil_events/core/events/event_extensions/manageable.rb
|
270
275
|
- lib/evil_events/core/events/event_extensions/metadata_extendable.rb
|
271
276
|
- lib/evil_events/core/events/event_extensions/metadata_extendable/abstract_metadata.rb
|
@@ -276,10 +281,18 @@ files:
|
|
276
281
|
- lib/evil_events/core/events/event_extensions/type_aliasing.rb
|
277
282
|
- lib/evil_events/core/events/event_factory.rb
|
278
283
|
- lib/evil_events/core/events/manager.rb
|
279
|
-
- lib/evil_events/core/events/manager/notifier.rb
|
280
284
|
- lib/evil_events/core/events/manager/subscriber_list.rb
|
281
285
|
- lib/evil_events/core/events/manager_factory.rb
|
282
286
|
- lib/evil_events/core/events/manager_registry.rb
|
287
|
+
- lib/evil_events/core/events/notifier.rb
|
288
|
+
- lib/evil_events/core/events/notifier/abstract.rb
|
289
|
+
- lib/evil_events/core/events/notifier/builder.rb
|
290
|
+
- lib/evil_events/core/events/notifier/logging.rb
|
291
|
+
- lib/evil_events/core/events/notifier/proxy.rb
|
292
|
+
- lib/evil_events/core/events/notifier/sequential.rb
|
293
|
+
- lib/evil_events/core/events/notifier/worker.rb
|
294
|
+
- lib/evil_events/core/events/notifier/worker/executor.rb
|
295
|
+
- lib/evil_events/core/events/notifier/worker/job.rb
|
283
296
|
- lib/evil_events/core/events/serializers.rb
|
284
297
|
- lib/evil_events/core/events/serializers/base.rb
|
285
298
|
- lib/evil_events/core/events/serializers/hash.rb
|
@@ -295,10 +308,11 @@ files:
|
|
295
308
|
- lib/evil_events/core/system/type_manager.rb
|
296
309
|
- lib/evil_events/dispatcher_mixin.rb
|
297
310
|
- lib/evil_events/emitter.rb
|
311
|
+
- lib/evil_events/error.rb
|
298
312
|
- lib/evil_events/event.rb
|
299
313
|
- lib/evil_events/plugins.rb
|
300
|
-
- lib/evil_events/plugins/
|
301
|
-
- lib/evil_events/plugins/
|
314
|
+
- lib/evil_events/plugins/redis_adapter.rb
|
315
|
+
- lib/evil_events/plugins/sidekiq_adapter.rb
|
302
316
|
- lib/evil_events/serializer.rb
|
303
317
|
- lib/evil_events/shared.rb
|
304
318
|
- lib/evil_events/shared/clonable_module_builder.rb
|
@@ -308,6 +322,7 @@ files:
|
|
308
322
|
- lib/evil_events/shared/crypto.rb
|
309
323
|
- lib/evil_events/shared/delegator_resolver.rb
|
310
324
|
- lib/evil_events/shared/dependency_container.rb
|
325
|
+
- lib/evil_events/shared/extensions_mixin.rb
|
311
326
|
- lib/evil_events/shared/logger.rb
|
312
327
|
- lib/evil_events/shared/structure.rb
|
313
328
|
- lib/evil_events/shared/type_converter.rb
|
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class EvilEvents::Core::Events::Manager
|
4
|
-
# @api private
|
5
|
-
# @since 0.1.0
|
6
|
-
module Notifier
|
7
|
-
# @since 0.1.0
|
8
|
-
NotifierError = Class.new(EvilEvents::Core::Error)
|
9
|
-
# @since 0.1.0
|
10
|
-
InconsistentEventClassError = Class.new(NotifierError)
|
11
|
-
|
12
|
-
# @since 0.1.0
|
13
|
-
class FailedSubscribersError < NotifierError
|
14
|
-
# @since 0.1.0
|
15
|
-
extend Forwardable
|
16
|
-
|
17
|
-
# @since 0.1.0
|
18
|
-
def_delegators :errors_stack, :<<, :empty?
|
19
|
-
|
20
|
-
# @return [Concurrent::Array]
|
21
|
-
#
|
22
|
-
# @api public
|
23
|
-
# @since 0.1.0
|
24
|
-
attr_reader :errors_stack
|
25
|
-
|
26
|
-
# @param message [NilClass, String]
|
27
|
-
#
|
28
|
-
# @since 0.1.0
|
29
|
-
def initialize(message = nil)
|
30
|
-
@errors_stack = Concurrent::Array.new
|
31
|
-
super
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class << self
|
36
|
-
# @param manager [EvilEvents::Core::Events::Manager]
|
37
|
-
# @param event [EvilEvents::Core::Events::AbstractEvent]
|
38
|
-
# @raise [InconsistentEventClassError]
|
39
|
-
# @raise [FailedSubscribersError]
|
40
|
-
# @return void
|
41
|
-
#
|
42
|
-
# @since 0.1.0
|
43
|
-
def run(manager, event)
|
44
|
-
raise InconsistentEventClassError unless event.is_a?(manager.event_class)
|
45
|
-
|
46
|
-
errors_stack = FailedSubscribersError.new
|
47
|
-
|
48
|
-
manager.subscribers.each do |subscriber|
|
49
|
-
begin
|
50
|
-
subscriber.notify(event)
|
51
|
-
log_activity(event, subscriber, :successful)
|
52
|
-
rescue StandardError => error
|
53
|
-
errors_stack << error
|
54
|
-
log_activity(event, subscriber, :failed)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
raise errors_stack unless errors_stack.empty?
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
# @param event [EvilEvents::Core::Events::AbstractEvent]
|
64
|
-
# @param subscriber [EvilEvents::Core::Events::Subscriber]
|
65
|
-
# @param status [String,Symbol]
|
66
|
-
# @return void
|
67
|
-
#
|
68
|
-
# @since 0.1.1
|
69
|
-
def log_activity(event, subscriber, status)
|
70
|
-
activity = "EventProcessed(#{event.type})"
|
71
|
-
message = "EVENT_ID: #{event.id} :: " \
|
72
|
-
"STATUS: #{status} :: " \
|
73
|
-
"SUBSCRIBER: #{subscriber.source_object}"
|
74
|
-
|
75
|
-
EvilEvents::Core::ActivityLogger.log(activity: activity, message: message)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|