evil_events 0.1.0rc8 → 0.1.0rc9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2dad67c5dd7b7585546efb878dc82d17d9d1d50
4
- data.tar.gz: 9c9f991e7bfcc3b0e9f43507af7f16c40191a191
3
+ metadata.gz: 427742fccaa575d930f2ae10f64ce3b31e2a511a
4
+ data.tar.gz: be655b351661f875c958c86efa678d20fe8c4961
5
5
  SHA512:
6
- metadata.gz: 554291095dc5c7f6677d9db008711f10659d86b050b1e261496dd5600c31354c494f245238f2a88978fa5ae39a298f87c37fe660007b3a8d365642a708ef719a
7
- data.tar.gz: 46a1d122aecb3517469d68365316507041b35ba10171c16973a5fbf2c3c3256dd1df141df981dde42f8114a746c3e7e76e3a481ea56a788fa79d1c6960ce0e08
6
+ metadata.gz: c7e7e6683b298bcf27244e9b5abd34c27a5e33ecd31ce39bc94406cc4b69cdb7830e6c09bc073d8aec00599ad1a0a8157566150d3739b43b13114f88198347df
7
+ data.tar.gz: c76f2a4ebfb393aea6aab83cf97fdede36e2298a841963a40e814969a1cfcd73cf19cb0ebcf95cf7ba7f0a2426afedb75e2df4e226584cfd4196aca58f55fcdf
data/README.md CHANGED
@@ -1,16 +1,5 @@
1
- # EvilEvents :imp: - event subsystem for ruby applications (work in progress!)
1
+ # EvilEvents - event subsystem for ruby applications (work in progress!)
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/evil_events.svg)](https://badge.fury.io/rb/evil_events)
4
4
  [![Build Status](https://travis-ci.org/ergosploit/evil_events.svg?branch=master)](https://travis-ci.org/ergosploit/evil_events)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/ergosploit/evil_events/badge.svg?branch=master)](https://coveralls.io/github/ergosploit/evil_events?branch=master)
6
-
7
- ### ROADMAP
8
- - Basic documentation (README) (0.1.0)
9
- - FULL documentation (0.1.1)
10
- - Notifier abstraction (0.2.0)
11
- - Event sourcing (0.3.0)
12
- - Concrete error messages for exceptions (0.1.1)
13
- - Hooks (0.2.0)
14
- - Custom logger formatters (0.2.0)
15
- - Logger colorization (0.2.0)
16
- - DRY specs (0.1.1)
@@ -42,7 +42,10 @@ module EvilEvents::Core::Broadcasting
42
42
  # @since 0.1.0
43
43
  def log_emitter_activity(event)
44
44
  activity = "EventEmitted(#{event.adapter_name})"
45
- message = "Type: #{event.type} :: Payload: #{event.payload} :: Metadata: #{event.metadata}"
45
+ message = "ID: #{event.id} :: " \
46
+ "TYPE: #{event.type} :: " \
47
+ "PAYLOAD: #{event.payload} :: " \
48
+ "METADATA: #{event.metadata}"
46
49
 
47
50
  EvilEvents::Core::ActivityLogger.log(activity: activity, message: message)
48
51
  end
@@ -24,17 +24,25 @@ module EvilEvents::Core::Events
24
24
  # @since 0.1.0
25
25
  extend EvilEvents::Shared::CombinedContext::Mixin
26
26
 
27
+ # @return [String]
28
+ #
29
+ # @api public
30
+ # @since 0.1.0
31
+ attr_reader :id
32
+
27
33
  # @option payload [Hash]
28
34
  # @option metadata [Hash]
29
35
  #
30
36
  # @since 0.1.0
31
37
  def initialize(payload: {}, metadata: {})
38
+ @id = EvilEvents::Shared::Crypto.uuid
32
39
  @payload = build_payload(**payload)
33
40
  @metadata = build_metadata(**metadata)
34
41
  end
35
42
 
36
43
  # @return [Hash]
37
44
  #
45
+ # @api public
38
46
  # @since 0.1.0
39
47
  def payload
40
48
  @payload.to_h
@@ -42,6 +50,7 @@ module EvilEvents::Core::Events
42
50
 
43
51
  # @return [Hash]
44
52
  #
53
+ # @api public
45
54
  # @since 0.1.0
46
55
  def metadata
47
56
  @metadata.to_h
@@ -0,0 +1,59 @@
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(StandardError)
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
+ def_delegators :errors_stack, :<<, :empty?
18
+
19
+ # @return [Concurrent::Array]
20
+ #
21
+ # @api public
22
+ # @since 0.1.0
23
+ attr_reader :errors_stack
24
+
25
+ # @param message [NilClass, String]
26
+ #
27
+ # @since 0.1.0
28
+ def initialize(message = nil)
29
+ @errors_stack = Concurrent::Array.new
30
+ super
31
+ end
32
+ end
33
+
34
+ class << self
35
+ # @param manager [EvilEvents::Core::Events::Manager]
36
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
37
+ # @raise [InconsistentEventClassError]
38
+ # @raise [FailedSubscribersError]
39
+ # @return void
40
+ #
41
+ # @since 0.1.0
42
+ def run(manager, event)
43
+ raise InconsistentEventClassError unless event.is_a?(manager.event_class)
44
+
45
+ errors_stack = FailedSubscribersError.new
46
+
47
+ manager.subscribers.each do |subscriber|
48
+ begin
49
+ subscriber.notify(event)
50
+ rescue StandardError => error
51
+ errors_stack << error
52
+ end
53
+ end
54
+
55
+ raise errors_stack unless errors_stack.empty?
56
+ end
57
+ end
58
+ end
59
+ end
@@ -45,14 +45,14 @@ module EvilEvents::Core::Events
45
45
  end
46
46
 
47
47
  # @param event [EvilEvents::Core::Events::AbstractEvent]
48
- # @raise [InconsistentEventClassError]
48
+ # @raise [Notifier::InconsistentEventClassError]
49
+ # @raise [Notifier::FailedSubscribersError]
50
+ #
49
51
  # @return void
50
52
  #
51
53
  # @since 0.1.0
52
54
  def notify(event)
53
- raise InconsistentEventClassError unless event.is_a?(event_class)
54
- # TODO: separate notification logic to worker/jobs
55
- subscribers.each { |subscriber| subscriber.notify(event) }
55
+ Notifier.run(self, event)
56
56
  end
57
57
 
58
58
  # @return [String, Symbol]
@@ -34,7 +34,7 @@ module EvilEvents::Core::Events
34
34
  #
35
35
  # @since 0.1.0
36
36
  def manager_of_event(event_class)
37
- # NOTE: raise exceptions to simplify runtime problems resolving
37
+ # NOTE: raise exceptions to simplify runtime problems
38
38
  managers[event_class] || (raise NonManagedEventClassError)
39
39
  end
40
40
 
@@ -19,6 +19,7 @@ module EvilEvents::Core
19
19
  require_relative 'events/event_extensions/emittable'
20
20
  require_relative 'events/abstract_event'
21
21
  require_relative 'events/manager'
22
+ require_relative 'events/manager/notifier'
22
23
  require_relative 'events/manager/subscriber_list'
23
24
  require_relative 'events/manager_factory'
24
25
  require_relative 'events/manager_registry'
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Shared
4
+ # @api public
5
+ # @since 0.1.0
6
+ module Crypto
7
+ module_function
8
+
9
+ # @return [String]
10
+ #
11
+ # @api public
12
+ # @since 0.1.0
13
+ def uuid
14
+ SecureRandom.uuid
15
+ end
16
+ end
17
+ end
@@ -6,6 +6,7 @@ module EvilEvents
6
6
  module Shared
7
7
  require_relative 'shared/types'
8
8
  require_relative 'shared/logger'
9
+ require_relative 'shared/crypto'
9
10
  require_relative 'shared/structure'
10
11
  require_relative 'shared/configurable'
11
12
  require_relative 'shared/combined_context'
@@ -3,5 +3,5 @@
3
3
  module EvilEvents
4
4
  # @api public
5
5
  # @since 0.1.0
6
- VERSION = '0.1.0rc8'
6
+ VERSION = '0.1.0rc9'
7
7
  end
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.1.0rc8
4
+ version: 0.1.0rc9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-25 00:00:00.000000000 Z
11
+ date: 2017-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads
@@ -270,6 +270,7 @@ files:
270
270
  - lib/evil_events/core/events/event_extensions/serializable.rb
271
271
  - lib/evil_events/core/events/event_extensions/type_aliasing.rb
272
272
  - lib/evil_events/core/events/manager.rb
273
+ - lib/evil_events/core/events/manager/notifier.rb
273
274
  - lib/evil_events/core/events/manager/subscriber_list.rb
274
275
  - lib/evil_events/core/events/manager_factory.rb
275
276
  - lib/evil_events/core/events/manager_registry.rb
@@ -293,6 +294,7 @@ files:
293
294
  - lib/evil_events/shared/combined_context.rb
294
295
  - lib/evil_events/shared/combined_context/mixin.rb
295
296
  - lib/evil_events/shared/configurable.rb
297
+ - lib/evil_events/shared/crypto.rb
296
298
  - lib/evil_events/shared/delegator_resolver.rb
297
299
  - lib/evil_events/shared/dependency_container.rb
298
300
  - lib/evil_events/shared/logger.rb