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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +2 -0
  3. data/.rubocop.yml +12 -0
  4. data/.travis.yml +3 -2
  5. data/CHANGELOG.md +18 -0
  6. data/evil_events.gemspec +3 -3
  7. data/lib/evil_events/application.rb +7 -0
  8. data/lib/evil_events/core/broadcasting/emitter.rb +5 -7
  9. data/lib/evil_events/core/config.rb +16 -1
  10. data/lib/evil_events/core/events/abstract_event.rb +2 -0
  11. data/lib/evil_events/core/events/event_extensions/class_signature/signature.rb +1 -1
  12. data/lib/evil_events/core/events/event_extensions/class_signature.rb +1 -1
  13. data/lib/evil_events/core/events/event_extensions/emittable.rb +29 -0
  14. data/lib/evil_events/core/events/event_extensions/hookable/abstract_hook.rb +27 -0
  15. data/lib/evil_events/core/events/event_extensions/hookable/after_emit_hook.rb +11 -0
  16. data/lib/evil_events/core/events/event_extensions/hookable/before_emit_hook.rb +11 -0
  17. data/lib/evil_events/core/events/event_extensions/hookable/on_error_hook.rb +16 -0
  18. data/lib/evil_events/core/events/event_extensions/hookable.rb +93 -0
  19. data/lib/evil_events/core/events/event_extensions/type_aliasing.rb +6 -12
  20. data/lib/evil_events/core/events/event_factory.rb +4 -4
  21. data/lib/evil_events/core/events/manager.rb +14 -12
  22. data/lib/evil_events/core/events/manager_factory.rb +2 -7
  23. data/lib/evil_events/core/events/manager_registry.rb +8 -15
  24. data/lib/evil_events/core/events/notifier/abstract.rb +26 -0
  25. data/lib/evil_events/core/events/notifier/builder.rb +43 -0
  26. data/lib/evil_events/core/events/notifier/logging.rb +43 -0
  27. data/lib/evil_events/core/events/notifier/proxy.rb +33 -0
  28. data/lib/evil_events/core/events/notifier/sequential.rb +41 -0
  29. data/lib/evil_events/core/events/notifier/worker/executor.rb +102 -0
  30. data/lib/evil_events/core/events/notifier/worker/job.rb +35 -0
  31. data/lib/evil_events/core/events/notifier/worker.rb +71 -0
  32. data/lib/evil_events/core/events/notifier.rb +6 -0
  33. data/lib/evil_events/core/events/serializers/hash.rb +9 -7
  34. data/lib/evil_events/core/events/serializers/json.rb +11 -6
  35. data/lib/evil_events/core/events/serializers.rb +0 -7
  36. data/lib/evil_events/core/events/subscriber/mixin.rb +2 -2
  37. data/lib/evil_events/core/events.rb +14 -1
  38. data/lib/evil_events/core/system/broadcaster.rb +23 -1
  39. data/lib/evil_events/core/system/mock.rb +7 -0
  40. data/lib/evil_events/core/system.rb +3 -1
  41. data/lib/evil_events/core.rb +0 -1
  42. data/lib/evil_events/error.rb +96 -0
  43. data/lib/evil_events/plugins/{rails.rb → redis_adapter.rb} +2 -2
  44. data/lib/evil_events/plugins/{elastic_search.rb → sidekiq_adapter.rb} +2 -2
  45. data/lib/evil_events/plugins.rb +15 -13
  46. data/lib/evil_events/shared/extensions_mixin.rb +7 -0
  47. data/lib/evil_events/shared/type_converter/converter_registry.rb +2 -2
  48. data/lib/evil_events/shared.rb +1 -0
  49. data/lib/evil_events/version.rb +1 -1
  50. data/lib/evil_events.rb +1 -0
  51. metadata +27 -12
  52. data/lib/evil_events/core/error.rb +0 -8
  53. data/lib/evil_events/core/events/manager/notifier.rb +0 -79
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ca82399f2d2f7e433c6dd9c111d2a6c3c285940
4
- data.tar.gz: 445c719e88bb2f1ff12720b8aec3fc62c451ef91
3
+ metadata.gz: e81af2ef5e25afbc5c4364b377c2b70720fa3d41
4
+ data.tar.gz: d9adbc345247a59247f3ac6b33ea09eefd604b4c
5
5
  SHA512:
6
- metadata.gz: c3ea9dfd03ec8f792d926d83ed2f014cc22ce8bb42d8730e626473ffb48d28bbfe2d2bdb990b9d2d279d8a3fc7a3fcb32d8d0c0ac2304a94a1a1418d096d57c6
7
- data.tar.gz: 4aa79a4f86765a4babbbc9aaea8c7a0947cc1f653a8c484b2496bc71daff8ce1a385b01c5665a265174f9f89a0f436a028a6b3f87022f17b9b6219bb69d27214
6
+ metadata.gz: dd67713c85af8fee6105d6df4d989a1060b527a125005e0fd7b113c73edbcfa9c033293b70798e0e2d33ebb3feb5a68044e0cadf71b49e773068b75f989de449
7
+ data.tar.gz: 67b06826b3ead1501c3b3c2b3d741d2addaf5a03d1752991ae176457f69c85f165adc65e7f4d6a857b912cb6557c772f3b5f70fa9ff101f20395aaf9d40a2e72
data/.hound.yml ADDED
@@ -0,0 +1,2 @@
1
+ ruby:
2
+ config_file: .rubocop.yml
data/.rubocop.yml CHANGED
@@ -53,9 +53,18 @@ Style/ParallelAssignment:
53
53
  Style/CommentedKeyword:
54
54
  Enabled: false
55
55
 
56
+ Style/EvalWithLocation:
57
+ Enabled: false
58
+
56
59
  Lint/AmbiguousRegexpLiteral:
57
60
  Enabled: false
58
61
 
62
+ Lint/HandleExceptions:
63
+ Enabled: false
64
+
65
+ Lint/UnusedBlockArgument:
66
+ Enabled: false
67
+
59
68
  Naming/FileName:
60
69
  Enabled: false
61
70
 
@@ -104,3 +113,6 @@ RSpec/LetSetup:
104
113
 
105
114
  RSpec/AnyInstance:
106
115
  Enabled: false
116
+
117
+ RSpec/ExpectChange:
118
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,12 +1,13 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.2.8
3
4
  - 2.3.5
4
5
  - 2.4.2
5
- - 2.2.8
6
+ - 2.5.0
6
7
  - ruby-head
7
8
  - jruby-head
8
9
 
9
10
  sudo: false
10
- before_install: gem install bundler -v 1.15.3
11
+ before_install: gem install bundler
11
12
  cache: bundler
12
13
  script: bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -1,6 +1,24 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.3.0] - 2018-02-25
5
+ ### Added
6
+ - Support for Ruby 2.5.0
7
+ - Introduce Event Emition Hooks API. Supported hooks (are decalred in an event class):
8
+ - `before_emit -> (event) {} # proc/lambda` - invoked once before an event emition process;
9
+ - `after_emit -> (event) {} # proc/lambda` - invoked once after an event emition process;
10
+ - `on_error -> (event, error) {} # proc/lambda` - invoked on each raised error due to emition process
11
+ (usually these errors are raised by subscribers and their's event processing methods)
12
+ - Added `AbstractEvent.emit!(**event_attributes)` method to provide an ability to emit events via event class constant.
13
+
14
+ ### Changed
15
+ - New more convenient exception hierarchy: now all exceptions live under `EvilEvents` namespace.
16
+ - Full refactoring of the event notification abstraction. New types of notifying processes:
17
+ - `sequential` (single-threaded): ordered notification logic, subscribers are notified one after the other;
18
+ - `worker` (multi-threaded): unordered notification logic, each subscriber is notified in own thread (depending on the settings);
19
+ - Process type should be globally pre-configured before application startup (new configuration options for each type of process);
20
+ - Notifier can be restarted via `EvilEvents::Application.restart_event_notifier` (it would be convenient to have an ability to reload/restart notifier object in development mode interactively).
21
+
4
22
  ## [0.2.0] - 2017-11-19
5
23
  ### Added
6
24
  - Support for custom coercive types:
data/evil_events.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  end
28
28
 
29
29
  spec.add_dependency 'dry-monads', '~> 0.4.0'
30
- spec.add_dependency 'dry-types', '~> 0.12.1'
30
+ spec.add_dependency 'dry-types', '~> 0.12.2'
31
31
  spec.add_dependency 'dry-struct', '~> 0.3.1'
32
32
  spec.add_dependency 'dry-configurable', '~> 0.7.0'
33
33
  spec.add_dependency 'dry-container', '~> 0.6.0'
@@ -36,9 +36,9 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency 'coveralls', '~> 0.8.21'
37
37
  spec.add_development_dependency 'simplecov', '~> 0.14.1'
38
38
  spec.add_development_dependency 'simplecov-json', '~> 0.2'
39
- spec.add_development_dependency 'rubocop', '~> 0.51.0'
39
+ spec.add_development_dependency 'rubocop', '~> 0.52.1'
40
40
  spec.add_development_dependency 'rspec', '~> 3.7.0'
41
- spec.add_development_dependency 'rubocop-rspec', '~> 1.20.1'
41
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.23.0'
42
42
 
43
43
  spec.add_development_dependency 'pry'
44
44
  spec.add_development_dependency 'rake'
@@ -11,6 +11,13 @@ module EvilEvents
11
11
  def registered_events
12
12
  EvilEvents::Core::Bootstrap[:event_system].registered_events
13
13
  end
14
+
15
+ # @see EvilEvents::Core::System
16
+ # @api public
17
+ # @since 0.3.0
18
+ def restart_event_notifier
19
+ EvilEvents::Core::Bootstrap[:event_system].restart_event_notifier
20
+ end
14
21
  end
15
22
  end
16
23
  end
@@ -4,18 +4,16 @@ module EvilEvents::Core::Broadcasting
4
4
  # @api private
5
5
  # @since 0.1.0
6
6
  class Emitter
7
- # @since 0.1.0
8
- EmitterError = Class.new(EvilEvents::Core::Error)
9
- # @since 0.1.0
10
- IncorrectEventError = Class.new(EmitterError)
11
-
12
7
  # @param event [EvilEvents::Core::Events::AbstractEvent]
13
- # @raise [IncorrectEventError]
8
+ # @raise [EvilEvents::IncorrectEventForEmitError]
14
9
  # @return void
15
10
  #
16
11
  # @since 0.1.0
17
12
  def emit(event)
18
- raise IncorrectEventError unless event.is_a?(EvilEvents::Core::Events::AbstractEvent)
13
+ unless event.is_a?(EvilEvents::Core::Events::AbstractEvent)
14
+ raise EvilEvents::IncorrectEventForEmitError
15
+ end
16
+
19
17
  log_activity(event)
20
18
  event.adapter.call(event)
21
19
  end
@@ -14,7 +14,7 @@ module EvilEvents::Core
14
14
 
15
15
  # @api private
16
16
  # @since 0.1.0
17
- def initialize
17
+ def initialize # rubocop:disable Metrics/AbcSize
18
18
  @config = Module.new do
19
19
  extend EvilEvents::Shared::Configurable
20
20
 
@@ -27,6 +27,21 @@ module EvilEvents::Core
27
27
  end
28
28
 
29
29
  setting :logger, EvilEvents::Shared::Logger.new(STDOUT), reader: true
30
+
31
+ setting :notifier, reader: true do
32
+ setting :type, :sequential
33
+
34
+ setting :sequential, reader: true do
35
+ # NOTE: place future settings here
36
+ end
37
+
38
+ setting :worker, reader: true do
39
+ setting :min_threads, 0
40
+ setting :max_threads, 5
41
+ setting :max_queue, 1000
42
+ setting :fallback_policy, :main_thread
43
+ end
44
+ end
30
45
  end
31
46
  end
32
47
 
@@ -23,6 +23,8 @@ module EvilEvents::Core::Events
23
23
  include EventExtensions::MetadataExtendable
24
24
  # @sicne 0.2.0
25
25
  include EventExtensions::ClassSignature
26
+ # @since 0.3.0
27
+ include EventExtensions::Hookable
26
28
  # @since 0.1.0
27
29
  extend EvilEvents::Shared::CombinedContext::Mixin
28
30
 
@@ -34,7 +34,7 @@ module EvilEvents::Core::Events::EventExtensions::ClassSignature
34
34
  #
35
35
  # @since 0.2.0
36
36
  def class_stamp
37
- { name: event_class.name, creation_strategy: event_class.__creation_strategy }
37
+ { name: event_class.name, creation_strategy: event_class.__creation_strategy__ }
38
38
  end
39
39
 
40
40
  # @return [String]
@@ -12,7 +12,7 @@ module EvilEvents::Core::Events::EventExtensions
12
12
  base_class.extend(ClassMethods)
13
13
 
14
14
  base_class.singleton_class.class_eval do
15
- attr_accessor :__creation_strategy
15
+ attr_accessor :__creation_strategy__
16
16
  end
17
17
  end
18
18
  end
@@ -4,9 +4,38 @@ module EvilEvents::Core::Events::EventExtensions
4
4
  # @api private
5
5
  # @since 0.1.0
6
6
  module Emittable
7
+ class << self
8
+ # @param base_class [Class{AbstractEvent}]
9
+ #
10
+ # @api private
11
+ # @since 0.3.0
12
+ def included(base_class)
13
+ base_class.extend(ClassMethods)
14
+ end
15
+ end
16
+
17
+ # @return void
18
+ #
19
+ # @api public
7
20
  # @since 0.1.0
8
21
  def emit!
9
22
  EvilEvents::Core::Bootstrap[:event_system].emit(self)
10
23
  end
24
+
25
+ module ClassMethods
26
+ # @option id [NilClass, Object]
27
+ # @option payload [Hash]
28
+ # @option metadata [Hash]
29
+ # @return void
30
+ #
31
+ # @see EvilEvents::Core::Events::AbstractEvent#initialize
32
+ # @see EvilEvents::Core::Events::EventExtensions::Emittable#emit!
33
+ #
34
+ # @api public
35
+ # @since 0.3.0
36
+ def emit!(**event_attributes)
37
+ new(**event_attributes).emit!
38
+ end
39
+ end
11
40
  end
12
41
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Events::EventExtensions::Hookable
4
+ # @api private
5
+ # @since 0.3.0
6
+ class AbstractHook
7
+ # @return [#call]
8
+ #
9
+ # @since 0.3.0
10
+ attr_reader :callable
11
+
12
+ # @param callable [#call]
13
+ #
14
+ # @since 0.3.0
15
+ def initialize(callable)
16
+ @callable = callable
17
+ end
18
+
19
+ # @param source [Object]
20
+ # @return void
21
+ #
22
+ # @since 0.3.0
23
+ def call(source)
24
+ callable.call(source)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Events::EventExtensions::Hookable
4
+ # @api private
5
+ # @since 0.3.0
6
+ class AfterEmitHook < AbstractHook
7
+ # @!method call(source)
8
+ # @param source [EvilEvents::Core::Events::AbstractEvent]
9
+ # @return void
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Events::EventExtensions::Hookable
4
+ # @api private
5
+ # @since 0.3.0
6
+ class BeforeEmitHook < AbstractHook
7
+ # @!method call(source)
8
+ # @param source [EvilEvents::Core::Events::AbstractEvent]
9
+ # @return void
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Events::EventExtensions::Hookable
4
+ # @api private
5
+ # @since 0.3.0
6
+ class OnErrorHook < AbstractHook
7
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
8
+ # @param error [StandardError]
9
+ # @return void
10
+ #
11
+ # @since 0.3.0
12
+ def call(event, error)
13
+ callable.call(event, error)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Events::EventExtensions
4
+ # @api private
5
+ # @since 0.3.0
6
+ module Hookable
7
+ class << self
8
+ # @param base_class [Class]
9
+ #
10
+ # @since 0.3.0
11
+ def included(base_class)
12
+ base_class.extend(ClassMethods)
13
+ end
14
+ end
15
+
16
+ # @param error [StandardError]
17
+ #
18
+ # @api private
19
+ # @since 0.3.0
20
+ def __call_on_error_hooks__(error)
21
+ self.class.__on_error_hooks__.each do |hook|
22
+ hook.call(self, error)
23
+ end
24
+ end
25
+
26
+ # @api private
27
+ # @since 0.3.0
28
+ def __call_before_hooks__
29
+ self.class.__before_emit_hooks__.each do |hook|
30
+ hook.call(self)
31
+ end
32
+ end
33
+
34
+ # @api private
35
+ # @since 0.3.0
36
+ def __call_after_hooks__
37
+ self.class.__after_emit_hooks__.each do |hook|
38
+ hook.call(self)
39
+ end
40
+ end
41
+
42
+ # @since 0.3.0
43
+ module ClassMethods
44
+ # @param hook [#call]
45
+ #
46
+ # @api public
47
+ # @since 0.3.0
48
+ def before_emit(hook)
49
+ __before_emit_hooks__ << BeforeEmitHook.new(hook)
50
+ end
51
+
52
+ # @param hook [#call]
53
+ #
54
+ # @api public
55
+ # @since 0.3.0
56
+ def after_emit(hook)
57
+ __after_emit_hooks__ << AfterEmitHook.new(hook)
58
+ end
59
+
60
+ # @param hook [#call]
61
+ #
62
+ # @api public
63
+ # @since 0.3.0
64
+ def on_error(hook)
65
+ __on_error_hooks__ << OnErrorHook.new(hook)
66
+ end
67
+
68
+ # @return [Concurrent::Array<BeforeHook>]
69
+ #
70
+ # @api private
71
+ # @since 0.3.0
72
+ def __before_emit_hooks__
73
+ @__before_emit_hooks__ ||= Concurrent::Array.new
74
+ end
75
+
76
+ # @return [Concurrent::Array<AfterHook>]
77
+ #
78
+ # @api private
79
+ # @since 0.3.0
80
+ def __after_emit_hooks__
81
+ @__after_emit_hooks__ ||= Concurrent::Array.new
82
+ end
83
+
84
+ # @return [Concurrent::Array<OnErrorHook>]
85
+ #
86
+ # @api private
87
+ # @since 0.3.0
88
+ def __on_error_hooks__
89
+ @__on_error_hooks__ ||= Concurrent::Array.new
90
+ end
91
+ end
92
+ end
93
+ end
@@ -4,15 +4,6 @@ module EvilEvents::Core::Events::EventExtensions
4
4
  # @api private
5
5
  # @since 0.1.0
6
6
  module TypeAliasing
7
- # @since 0.1.0
8
- TypeAliasingError = Class.new(EvilEvents::Core::Error)
9
- # @since 0.1.0
10
- IncopatibleEventTypeError = Class.new(TypeAliasingError)
11
- # @since 0.1.0
12
- EventTypeNotDefinedError = Class.new(TypeAliasingError)
13
- # @since 0.1.0
14
- EventTypeAlreadyDefinedError = Class.new(TypeAliasingError)
15
-
16
7
  class << self
17
8
  # @param base_class [Class]
18
9
  #
@@ -31,17 +22,20 @@ module EvilEvents::Core::Events::EventExtensions
31
22
 
32
23
  module ClassMethods
33
24
  # @param type_alias [String, NilClass]
25
+ # @raise [EvilEvents::IncopatibleEventTypeError]
26
+ # @raise [EvilEvents::EventTypeNotDefinedError]
27
+ # @raise [EvilEvents::EventTypeAlreadyDefinedError]
34
28
  # @return [String]
35
29
  #
36
30
  # @since 0.1.0
37
31
  def type(type_alias = nil)
38
32
  case
39
33
  when incompatible_type_alias_type?(type_alias)
40
- raise IncopatibleEventTypeError
34
+ raise EvilEvents::IncopatibleEventTypeError
41
35
  when fetching_type_alias_when_type_alias_not_defined?(type_alias)
42
- raise EventTypeNotDefinedError
36
+ raise EvilEvents::EventTypeNotDefinedError
43
37
  when providing_type_alias_when_type_alias_already_defined?(type_alias)
44
- raise EventTypeAlreadyDefinedError
38
+ raise EvilEvents::EventTypeAlreadyDefinedError
45
39
  when tries_to_define_type_alias_first_time?(type_alias)
46
40
  @type = type_alias
47
41
  end
@@ -19,14 +19,14 @@ module EvilEvents::Core::Events
19
19
  def create_abstract_class(event_type)
20
20
  Class.new(AbstractEvent).tap do |klass|
21
21
  klass.type(event_type)
22
- klass.__creation_strategy = CLASS_INHERITANCE_STRATEGY
22
+ klass.__creation_strategy__ = CLASS_INHERITANCE_STRATEGY
23
23
 
24
24
  class << klass
25
25
  def inherited(child_class)
26
26
  child_class.type(type)
27
- child_class.__creation_strategy = CLASS_INHERITANCE_STRATEGY
27
+ child_class.__creation_strategy__ = CLASS_INHERITANCE_STRATEGY
28
28
  child_class.manage!
29
- rescue EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError
29
+ rescue EvilEvents::AlreadyManagedEventClassError
30
30
  EvilEvents::Core::Bootstrap[:event_system].unregister_event_class(child_class)
31
31
  raise
32
32
  end
@@ -44,7 +44,7 @@ module EvilEvents::Core::Events
44
44
  def create_class(event_type, &event_class_definitions)
45
45
  Class.new(AbstractEvent).tap do |klass|
46
46
  begin
47
- klass.__creation_strategy = PROC_EVAL_STRATEGY
47
+ klass.__creation_strategy__ = PROC_EVAL_STRATEGY
48
48
  klass.type(event_type)
49
49
  klass.manage!
50
50
  klass.evaluate(&event_class_definitions) if block_given?
@@ -4,13 +4,6 @@ module EvilEvents::Core::Events
4
4
  # @api private
5
5
  # @since 0.1.0
6
6
  class Manager
7
- # @since 0.1.0
8
- ManagerError = Class.new(EvilEvents::Core::Error)
9
- # @since 0.1.0
10
- InconsistentEventClassError = Class.new(ManagerError)
11
- # @since 0.1.0
12
- InvalidDelegatorTypeError = Class.new(ManagerError)
13
-
14
7
  # @return [EvilEvents::Core::Events::AbstractEvent]
15
8
  #
16
9
  # @since 0.1.0
@@ -31,7 +24,7 @@ module EvilEvents::Core::Events
31
24
 
32
25
  # @param raw_subscriber [Object]
33
26
  # @param delegator [Symbol, String, NilClass]
34
- # @raise [InvalidDelegatorTypeError]
27
+ # @raise [EvilEvents::InvalidDelegatorTypeError]
35
28
  # @return void
36
29
  #
37
30
  # @since 0.1.0
@@ -40,19 +33,20 @@ module EvilEvents::Core::Events
40
33
  when NilClass, Symbol, String
41
34
  subscribers.push(create_event_subscriber(raw_subscriber, delegator))
42
35
  else
43
- raise InvalidDelegatorTypeError
36
+ raise EvilEvents::InvalidDelegatorTypeError
44
37
  end
45
38
  end
46
39
 
47
40
  # @param event [EvilEvents::Core::Events::AbstractEvent]
48
- # @raise [Notifier::InconsistentEventClassError]
49
- # @raise [Notifier::FailedSubscribersError]
41
+ # @raise [EvilEvents::InconsistentEventClassError]
42
+ # @raise [EvilEvents::FailedNotifiedSubscribersError]
50
43
  #
51
44
  # @return void
52
45
  #
53
46
  # @since 0.1.0
54
47
  def notify(event)
55
- Notifier.run(self, event)
48
+ raise EvilEvents::InconsistentEventClassError unless supported_event?(event)
49
+ EvilEvents::Core::Bootstrap[:event_system].process_event_notification(self, event)
56
50
  end
57
51
 
58
52
  # @return [String, Symbol]
@@ -64,6 +58,14 @@ module EvilEvents::Core::Events
64
58
 
65
59
  private
66
60
 
61
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
62
+ # @return [Boolean]
63
+ #
64
+ # @since 0.3.0
65
+ def supported_event?(event)
66
+ event.is_a?(event_class)
67
+ end
68
+
67
69
  # @param raw_subscriber [Object]
68
70
  # @param delegator [Symbol, String, NilClass]
69
71
  # @return [EvilEvents::Core::Events::Subscriber]
@@ -4,20 +4,15 @@ module EvilEvents::Core::Events
4
4
  # @api private
5
5
  # @since 0.1.0
6
6
  module ManagerFactory
7
- # @since 0.1.0
8
- ManagerFactoryError = Class.new(EvilEvents::Core::Error)
9
- # @since 0.1.0
10
- IncorrectEventClassError = Class.new(ManagerFactoryError)
11
-
12
7
  class << self
13
8
  # @param event_class [Class{EvilEvents::Core::Events::AbstractEvent}]
14
- # @raise [IncorrectEventClassError]
9
+ # @raise [EvilEvents::IncorrectEventClassError]
15
10
  # @return [EvilEvents::Core::Events::Manager]
16
11
  #
17
12
  # @since 0.1.0
18
13
  def create(event_class)
19
14
  unless event_class.is_a?(Class) && event_class < EvilEvents::Core::Events::AbstractEvent
20
- raise IncorrectEventClassError
15
+ raise EvilEvents::IncorrectEventClassError
21
16
  end
22
17
 
23
18
  Manager.new(event_class)
@@ -7,15 +7,6 @@ module EvilEvents::Core::Events
7
7
  # @since 0.1.0
8
8
  extend Forwardable
9
9
 
10
- # @since 0.1.0
11
- ManagerRegistryError = Class.new(EvilEvents::Core::Error)
12
- # @since 0.1.0
13
- IncorrectManagerObjectError = Class.new(ManagerRegistryError)
14
- # @since 0.1.0
15
- NonManagedEventClassError = Class.new(ManagerRegistryError)
16
- # @since 0.1.0
17
- AlreadyManagedEventClassError = Class.new(ManagerRegistryError)
18
-
19
10
  # @since 0.1.0
20
11
  def_delegators :managers, :empty?, :size
21
12
 
@@ -30,13 +21,13 @@ module EvilEvents::Core::Events
30
21
  end
31
22
 
32
23
  # @param event_class [Class{EvilEvents::Core::Events::AbstractEvent}]
33
- # @raise [NonManagedEventClassError]
24
+ # @raise [EvilEvents::NonManagedEventClassError]
34
25
  # @return [EvilEvents::Core::Events::Manager]
35
26
  #
36
27
  # @since 0.1.0
37
28
  def manager_of_event(event_class)
38
29
  # NOTE: raise exceptions to simplify runtime problems
39
- managers[event_class] || (raise NonManagedEventClassError)
30
+ managers[event_class] || (raise EvilEvents::NonManagedEventClassError)
40
31
  end
41
32
 
42
33
  # @param event_type [String]
@@ -77,18 +68,20 @@ module EvilEvents::Core::Events
77
68
  end
78
69
 
79
70
  # @param manager [EvilEvents::Core::Events::Manager]
80
- # @raise [IncorrectManagerObjectError]
81
- # @raise [AlreadyManagedEventClassError]
71
+ # @raise [EvilEvents::IncorrectManagerObjectError]
72
+ # @raise [EvilEvents::AlreadyManagedEventClassError]
82
73
  # @return void
83
74
  #
84
75
  # @since 0.1.0
85
76
  def register(manager)
86
- raise IncorrectManagerObjectError unless manager.is_a?(EvilEvents::Core::Events::Manager)
77
+ unless manager.is_a?(EvilEvents::Core::Events::Manager)
78
+ raise EvilEvents::IncorrectManagerObjectError
79
+ end
87
80
 
88
81
  if potential_manager_duplicate?(manager) || !managed_event_type?(manager.event_type)
89
82
  managers[manager.event_class] = manager
90
83
  else
91
- raise AlreadyManagedEventClassError
84
+ raise EvilEvents::AlreadyManagedEventClassError
92
85
  end
93
86
  end
94
87
 
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api private
4
+ # @since 0.3.0
5
+ class EvilEvents::Core::Events::Notifier::Abstract
6
+ # @param options [Hash]
7
+ #
8
+ # @api private
9
+ # @since 0.3.0
10
+ def initialize(**options); end
11
+
12
+ # @param manager [EvilEvents::Core::Events::Manager]
13
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
14
+ #
15
+ # @api private
16
+ # @since 0.3.0
17
+ def notify(manager, event); end
18
+
19
+ # @api private
20
+ # @since 0.3.0
21
+ def restart!; end
22
+
23
+ # @api private
24
+ # @since 0.3.0
25
+ def shutdown!; end
26
+ end