evil_events 0.1.0rc1 → 0.1.0rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/CHANGELOG.md +2 -0
  4. data/README.md +4 -2
  5. data/evil_events.gemspec +9 -7
  6. data/lib/evil_events/boot_point.rb +4 -8
  7. data/lib/evil_events/config.rb +7 -0
  8. data/lib/evil_events/core/activity_logging.rb +2 -2
  9. data/lib/evil_events/core/broadcasting/adapters/memory_async.rb +13 -8
  10. data/lib/evil_events/core/broadcasting/adapters/memory_sync.rb +11 -9
  11. data/lib/evil_events/core/broadcasting/adapters.rb +2 -2
  12. data/lib/evil_events/core/broadcasting/dispatcher/{dispatchable.rb → mixin.rb} +1 -1
  13. data/lib/evil_events/core/broadcasting/dispatcher.rb +1 -1
  14. data/lib/evil_events/core/broadcasting/emitter.rb +10 -2
  15. data/lib/evil_events/core/broadcasting.rb +1 -1
  16. data/lib/evil_events/core/events/abstract_event.rb +4 -1
  17. data/lib/evil_events/core/events/event_class_factory.rb +8 -12
  18. data/lib/evil_events/core/events/event_extensions/adapter_customizable.rb +2 -2
  19. data/lib/evil_events/core/events/event_extensions/emittable.rb +12 -0
  20. data/lib/evil_events/core/events/event_extensions/manageable.rb +1 -1
  21. data/lib/evil_events/core/events/event_extensions/observable.rb +3 -3
  22. data/lib/evil_events/core/events/event_extensions/payloadable.rb +1 -1
  23. data/lib/evil_events/core/events/event_extensions/serializable.rb +2 -0
  24. data/lib/evil_events/core/events/manager_factory.rb +10 -0
  25. data/lib/evil_events/core/events/serializers/hash.rb +1 -1
  26. data/lib/evil_events/core/events/serializers/json.rb +1 -1
  27. data/lib/evil_events/core/events/subscriber/mixin.rb +2 -2
  28. data/lib/evil_events/core/events/subscriber.rb +11 -1
  29. data/lib/evil_events/core/events.rb +1 -0
  30. data/lib/evil_events/core.rb +1 -0
  31. data/lib/evil_events/shared/combined_context.rb +2 -0
  32. data/lib/evil_events/shared/logger.rb +1 -1
  33. data/lib/evil_events/shared.rb +6 -5
  34. data/lib/evil_events/system/broadcaster.rb +42 -0
  35. data/lib/evil_events/system/event_builder.rb +30 -0
  36. data/lib/evil_events/system/event_manager.rb +95 -0
  37. data/lib/evil_events/system/mock.rb +7 -3
  38. data/lib/evil_events/system/mocking.rb +33 -0
  39. data/lib/evil_events/system.rb +34 -125
  40. data/lib/evil_events/version.rb +1 -1
  41. data/lib/evil_events.rb +5 -5
  42. metadata +37 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d92142f28955faa9a09b89fd4e49d90ee6d916c
4
- data.tar.gz: 8e1db3af52fabe05fe15328f6fe096d7cca34f4c
3
+ metadata.gz: 7a6c5ea4454784cde26a98119cba57b5d593b38a
4
+ data.tar.gz: f6966cb8fa6f63a8a81185ebb7ed27135325972b
5
5
  SHA512:
6
- metadata.gz: ba2407d8d151584caee50926f92bc7ffa766dc996ba79f8a7c6c175edc83296e9bb3a83ba49621afe13122c0fd0bd4c86015070e5bd9ed8e66d327e5ea362268
7
- data.tar.gz: afc02be9c2ffc74d5b02e5bb8c7ccfb420e3fd13efc9838df62257ee6504ca562a051af252b1a33c2a3e568fbda79a3d45b9c375e9438ab52728688c248409d5
6
+ metadata.gz: 5318459757e376efd82ab5a05bead86551b44b18948348523123777fe42a237f8d069e7fa79a19e4cb78a034c85b1be45d758e53a8dc7b261362f86cbfeb6c3f
7
+ data.tar.gz: 384d7919a39d38a2998cc2663c14ec6ff453c6012668eae704321d4a1a1bfae413f44c585d263a295b091fa4d948c4cf0dc43b536ea74419ea8332d5674f8a73
data/.travis.yml CHANGED
@@ -6,5 +6,7 @@ rvm:
6
6
  - ruby-head
7
7
  - jruby-head
8
8
 
9
+ env: JRUBY_OPTS=--debug
9
10
  sudo: false
10
11
  before_install: gem install bundler -v 1.15.3
12
+ cache: bundler
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # EvilEvents - powerful event system for ruby applications
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/evil_events.svg)](https://badge.fury.io/rb/evil_events)
4
+ [![Build Status](https://travis-ci.org/ergosploit/evil_events.svg?branch=master)](https://travis-ci.org/ergosploit/evil_events)
5
+ [![Coverage Status](https://coveralls.io/repos/github/ergosploit/evil_events/badge.svg?branch=master)](https://coveralls.io/github/ergosploit/evil_events?branch=master)
4
6
 
5
- Note: work in progress!
7
+ NOTE: Work in progress!
6
8
 
7
- ### TODO
9
+ ### ROADMAP
8
10
  - Full test coverage (0.1.0)
9
11
  - Basic documentation (README) (0.1.0)
10
12
  - FULL documentation (0.2.1)
data/evil_events.gemspec CHANGED
@@ -32,11 +32,13 @@ Gem::Specification.new do |spec|
32
32
  spec.add_dependency 'dry-container', '0.6.0'
33
33
  spec.add_dependency 'concurrent-ruby', '1.0.5'
34
34
 
35
- spec.add_development_dependency 'pry', '0.11.1'
36
- spec.add_development_dependency 'simplecov', '0.15.1'
37
- spec.add_development_dependency 'rubocop', '0.50.0'
38
- spec.add_development_dependency 'bundler', '1.15.4'
39
- spec.add_development_dependency 'rake', '12.1.0'
40
- spec.add_development_dependency 'rspec', '3.6.0'
41
- spec.add_development_dependency 'rubocop-rspec', '1.18.0'
35
+ spec.add_development_dependency 'coveralls', '0.7.2'
36
+ spec.add_development_dependency 'pry', '0.11.1'
37
+ spec.add_development_dependency 'simplecov', '0.15.1'
38
+ spec.add_development_dependency 'simplecov-json', '0.2'
39
+ spec.add_development_dependency 'rubocop', '0.50.0'
40
+ spec.add_development_dependency 'bundler', '1.15.4'
41
+ spec.add_development_dependency 'rake', '12.1.0'
42
+ spec.add_development_dependency 'rspec', '3.6.0'
43
+ spec.add_development_dependency 'rubocop-rspec', '1.18.0'
42
44
  end
@@ -3,15 +3,11 @@
3
3
  module EvilEvents
4
4
  # @api private
5
5
  # @since 0.1.0
6
- module BootPoint
7
- # @api private
6
+ class BootPoint
8
7
  # @since 0.1.0
9
- class System
10
- # @since 0.1.0
11
- extend Shared::DependencyContainer::Mixin
8
+ extend Shared::DependencyContainer::Mixin
12
9
 
13
- register(:event_system, memoize: true) { EvilEvents::System.new }
14
- register(:config) { EvilEvents::Config }
15
- end
10
+ register(:event_system, memoize: true) { EvilEvents::System.new }
11
+ register(:config) { EvilEvents::Config }
16
12
  end
17
13
  end
@@ -7,6 +7,13 @@ module EvilEvents
7
7
  extend EvilEvents::Shared::Configurable
8
8
 
9
9
  class << self
10
+ # @return [Class{EvilEvents::Shared::Configurable}]
11
+ #
12
+ # @since 0.1.0
13
+ def build_stub
14
+ build_mock
15
+ end
16
+
10
17
  # @return void
11
18
  #
12
19
  # @since 0.1.0
@@ -9,7 +9,7 @@ module EvilEvents::Core
9
9
  # @return void
10
10
  #
11
11
  # @since 0.1.0
12
- def log_activity(activity = nil, message = nil)
12
+ def log_activity(activity: nil, message: nil)
13
13
  progname = "[EvilEvents:#{activity}]"
14
14
  activity_logger.add(activity_logger.level, message, progname)
15
15
  end
@@ -18,7 +18,7 @@ module EvilEvents::Core
18
18
  #
19
19
  # @since 0.1.0
20
20
  def activity_logger
21
- EvilEvents::BootPoint::System[:config].logger
21
+ EvilEvents::BootPoint[:config].logger
22
22
  end
23
23
  end
24
24
  end
@@ -4,16 +4,21 @@ module EvilEvents::Core::Broadcasting
4
4
  class Adapters
5
5
  # @api public
6
6
  # @since 0.1.0
7
- class MemoryAsync
7
+ module MemoryAsync
8
8
  # @since 0.1.0
9
- include Dispatcher::Dispatchable
9
+ AsyncTask = ::Thread
10
10
 
11
- # @param event [EvilEvents::Core::Events::AbstractEvent]
12
- # @return void
13
- #
14
- # @since 0.1.0
15
- def call(event)
16
- ::Thread.new { dispatch(event) }
11
+ class << self
12
+ # @since 0.1.0
13
+ include Dispatcher::Mixin
14
+
15
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
16
+ # @return void
17
+ #
18
+ # @since 0.1.0
19
+ def call(event)
20
+ AsyncTask.new { dispatch(event) }
21
+ end
17
22
  end
18
23
  end
19
24
  end
@@ -4,16 +4,18 @@ module EvilEvents::Core::Broadcasting
4
4
  class Adapters
5
5
  # @api public
6
6
  # @since 0.1.0
7
- class MemorySync
8
- # @since 0.1.0
9
- include Dispatcher::Dispatchable
7
+ module MemorySync
8
+ class << self
9
+ # @since 0.1.0
10
+ include Dispatcher::Mixin
10
11
 
11
- # @param event [EvilEvents::Core::Events::AbstractEvent]
12
- # @return void
13
- #
14
- # @since 0.1.0
15
- def call(event)
16
- dispatch(event)
12
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
13
+ # @return void
14
+ #
15
+ # @since 0.1.0
16
+ def call(event)
17
+ dispatch(event)
18
+ end
17
19
  end
18
20
  end
19
21
  end
@@ -5,7 +5,7 @@ module EvilEvents::Core::Broadcasting
5
5
  class Adapters
6
6
  extend EvilEvents::Shared::DependencyContainer::Mixin
7
7
 
8
- register :memory_sync, -> { Adapters::MemorySync.new }
9
- register :memory_async, -> { Adapters::MemoryAsync.new }
8
+ register(:memory_sync) { Adapters::MemorySync }
9
+ register(:memory_async) { Adapters::MemoryAsync }
10
10
  end
11
11
  end
@@ -4,7 +4,7 @@ module EvilEvents::Core::Broadcasting
4
4
  class Dispatcher
5
5
  # @api public
6
6
  # @since 0.1.0
7
- module Dispatchable
7
+ module Mixin
8
8
  # @param event [EvilEvents::Core::Events::AbstractEvent]
9
9
  # @return void
10
10
  #
@@ -10,7 +10,7 @@ module EvilEvents::Core::Broadcasting
10
10
  #
11
11
  # @since 0.1.0
12
12
  def dispatch(event) # Broadcast
13
- EvilEvents::BootPoint::System[:event_system].manager_of_event(event).notify(event)
13
+ EvilEvents::BootPoint[:event_system].manager_of_event(event).notify(event)
14
14
  end
15
15
  end
16
16
  end
@@ -7,11 +7,18 @@ module EvilEvents::Core::Broadcasting
7
7
  # @since 0.1.0
8
8
  include EvilEvents::Core::ActivityLogging
9
9
 
10
+ # @since 0.1.0
11
+ EmitterError = Class.new(StandardError)
12
+ # @since 0.1.0
13
+ IncorrectEventError = Class.new(EmitterError)
14
+
10
15
  # @param event [EvilEvents::Core::Events::AbstractEvent]
16
+ # @raise [IncorrectEventError]
11
17
  # @return void
12
18
  #
13
19
  # @since 0.1.0
14
20
  def emit(event)
21
+ raise IncorrectEventError unless event.is_a?(EvilEvents::Core::Events::AbstractEvent)
15
22
  log_emitter_activity(event)
16
23
  event.adapter.call(event)
17
24
  end
@@ -22,7 +29,7 @@ module EvilEvents::Core::Broadcasting
22
29
  #
23
30
  # @since 0.1.0
24
31
  def raw_emit(event_type, **event_attributes)
25
- event_object = EvilEvents::BootPoint::System[:event_system].resolve_event_object(
32
+ event_object = EvilEvents::BootPoint[:event_system].resolve_event_object(
26
33
  event_type,
27
34
  **event_attributes
28
35
  )
@@ -39,7 +46,8 @@ module EvilEvents::Core::Broadcasting
39
46
  def log_emitter_activity(event)
40
47
  activity = "EventEmitted(#{event.adapter_name})"
41
48
  message = "Type: #{event.type} :: Payload: #{event.payload}"
42
- log_activity(activity, message)
49
+
50
+ log_activity(activity: activity, message: message)
43
51
  end
44
52
  end
45
53
  end
@@ -4,7 +4,7 @@ module EvilEvents::Core
4
4
  # @since 0.1.0
5
5
  module Broadcasting
6
6
  require_relative 'broadcasting/dispatcher'
7
- require_relative 'broadcasting/dispatcher/dispatchable'
7
+ require_relative 'broadcasting/dispatcher/mixin'
8
8
  require_relative 'broadcasting/adapters'
9
9
  require_relative 'broadcasting/adapters/memory_sync'
10
10
  require_relative 'broadcasting/adapters/memory_async'
@@ -18,12 +18,15 @@ module EvilEvents::Core::Events
18
18
  # @since 0.1.0
19
19
  include EventExtensions::Serializable
20
20
  # @since 0.1.0
21
+ include EventExtensions::Emittable
22
+ # @since 0.1.0
21
23
  extend EvilEvents::Shared::CombinedContextMixin
22
24
 
23
25
  # @param payload_attributes [Hash]
24
26
  #
25
27
  # @since 0.1.0
26
28
  def initialize(**payload_attributes)
29
+ @uuid = SecureRandom.uuid # TODO: cover with a spec (uuid belongs to metadata)
27
30
  @payload = payload_class.new(**payload_attributes)
28
31
  end
29
32
 
@@ -38,7 +41,7 @@ module EvilEvents::Core::Events
38
41
  #
39
42
  # @since 0.1.0
40
43
  def emit
41
- EvilEvents::BootPoint::System[:event_system].emit(self)
44
+ EvilEvents::BootPoint[:event_system].emit(self)
42
45
  end
43
46
  end
44
47
  end
@@ -7,7 +7,7 @@ module EvilEvents::Core::Events
7
7
  class << self
8
8
  # @param event_type [String]
9
9
  # @raise [EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError]
10
- # @return [AbstractEvent]
10
+ # @return [Class{EvilEvents::Core::Events::AbstractEvent}]
11
11
  #
12
12
  # @since 0.1.0
13
13
  def create_abstract(event_type)
@@ -16,15 +16,11 @@ module EvilEvents::Core::Events
16
16
 
17
17
  class << klass
18
18
  def inherited(child_class)
19
- begin
20
- child_class.type(type)
21
- child_class.manage!
22
- rescue EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError
23
- EvilEvents::BootPoint::System[:event_system].unregister_event_class(child_class)
24
- raise
25
- end
26
-
27
- super
19
+ child_class.type(type)
20
+ child_class.manage!
21
+ rescue EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError
22
+ EvilEvents::BootPoint[:event_system].unregister_event_class(child_class)
23
+ raise
28
24
  end
29
25
  end
30
26
  end
@@ -34,7 +30,7 @@ module EvilEvents::Core::Events
34
30
  # @param event_class_definitions [Proc]
35
31
  # @yield [AbstractEvent]
36
32
  # @raise [EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError]
37
- # @return [AbstractEvent]
33
+ # @return [Class{EvilEvents::Core::Events::AbstractEvent}]
38
34
  #
39
35
  # @since 0.1.0
40
36
  def create(event_type, &event_class_definitions)
@@ -44,7 +40,7 @@ module EvilEvents::Core::Events
44
40
  klass.manage!
45
41
  klass.evaluate(&event_class_definitions) if block_given?
46
42
  rescue EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError
47
- EvilEvents::BootPoint::System[:event_system].unregister_event_class(klass)
43
+ EvilEvents::BootPoint[:event_system].unregister_event_class(klass)
48
44
  raise
49
45
  end
50
46
  end
@@ -35,14 +35,14 @@ module EvilEvents::Core::Events::EventExtensions
35
35
  # @since 0.1.0
36
36
  def adapter(identifier = nil)
37
37
  @adapter_identifier = identifier if identifier
38
- EvilEvents::BootPoint::System[:event_system].resolve_adapter(adapter_name)
38
+ EvilEvents::BootPoint[:event_system].resolve_adapter(adapter_name)
39
39
  end
40
40
 
41
41
  # @return [Symbol, String]
42
42
  #
43
43
  # @since 0.1.0
44
44
  def adapter_name
45
- @adapter_identifier || EvilEvents::BootPoint::System[:config].adapter.default
45
+ @adapter_identifier || EvilEvents::BootPoint[:config].adapter.default
46
46
  end
47
47
  end
48
48
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Events::EventExtensions
4
+ # @api private
5
+ # @since 0.1.0
6
+ module Emittable
7
+ # @since 0.1.0
8
+ def emit!
9
+ EvilEvents::BootPoint[:event_system].emit(self)
10
+ end
11
+ end
12
+ end
@@ -19,7 +19,7 @@ module EvilEvents::Core::Events::EventExtensions
19
19
  #
20
20
  # @since 0.1.0
21
21
  def manage!
22
- EvilEvents::BootPoint::System[:event_system].register_event_class(self)
22
+ EvilEvents::BootPoint[:event_system].register_event_class(self)
23
23
  end
24
24
  end
25
25
  end
@@ -27,7 +27,7 @@ module EvilEvents::Core::Events::EventExtensions
27
27
  #
28
28
  # @since 0.1.0
29
29
  def observe(raw_subscriber, delegator: nil)
30
- EvilEvents::BootPoint::System[:event_system].observe(self, raw_subscriber, delegator)
30
+ EvilEvents::BootPoint[:event_system].observe(self, raw_subscriber, delegator)
31
31
  end
32
32
 
33
33
  # @param delegator [Symbol, String, NilClass]
@@ -35,14 +35,14 @@ module EvilEvents::Core::Events::EventExtensions
35
35
  # @since 0.1.0
36
36
  def default_delegator(delegator = nil)
37
37
  @default_delegator = delegator if delegator
38
- @default_delegator || EvilEvents::BootPoint::System[:config].subscriber.default_delegator
38
+ @default_delegator || EvilEvents::BootPoint[:config].subscriber.default_delegator
39
39
  end
40
40
 
41
41
  # @return [Array]
42
42
  #
43
43
  # @since 0.1.0
44
44
  def observers
45
- EvilEvents::BootPoint::System[:event_system].observers(self)
45
+ EvilEvents::BootPoint[:event_system].observers(self)
46
46
  end
47
47
  end
48
48
  end
@@ -37,7 +37,7 @@ module EvilEvents::Core::Events::EventExtensions
37
37
  # @return void
38
38
  #
39
39
  # @since 0.1.0
40
- def attribute(key, type = EvilEvents::Shared::Types::Any)
40
+ def attribute(key, type = EvilEvents::Types::Any)
41
41
  const_get(:Payload).attribute(key, type)
42
42
  end
43
43
 
@@ -10,6 +10,7 @@ module EvilEvents::Core::Events::EventExtensions
10
10
  def serialize_to_hash
11
11
  EvilEvents::Core::Events::Serializers[:hash].serialize(self)
12
12
  end
13
+ alias_method :dump_to_hash, :serialize_to_hash
13
14
 
14
15
  # @return [String]
15
16
  #
@@ -17,5 +18,6 @@ module EvilEvents::Core::Events::EventExtensions
17
18
  def serialize_to_json
18
19
  EvilEvents::Core::Events::Serializers[:json].serialize(self)
19
20
  end
21
+ alias_method :dump_to_json, :serialize_to_json
20
22
  end
21
23
  end
@@ -4,12 +4,22 @@ 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(StandardError)
9
+ # @sicne 0.1.0
10
+ IncorrectEventClassError = Class.new(ManagerFactoryError)
11
+
7
12
  class << self
8
13
  # @param event_class [Class{EvilEvents::Core::Events::AbstractEvent}]
14
+ # @raise [IncorrectEventClassError]
9
15
  # @return [EvilEvents::Core::Events::Manager]
10
16
  #
11
17
  # @since 0.1.0
12
18
  def create(event_class)
19
+ unless event_class.is_a?(Class) && event_class < EvilEvents::Core::Events::AbstractEvent
20
+ raise IncorrectEventClassError
21
+ end
22
+
13
23
  Manager.new(event_class)
14
24
  end
15
25
  end
@@ -29,7 +29,7 @@ class EvilEvents::Core::Events::Serializers
29
29
  raise DeserializationError unless event_type && event_payload
30
30
  raise DeserializationError unless event_payload.is_a?(::Hash)
31
31
 
32
- EvilEvents::BootPoint::System[:event_system].resolve_event_object(
32
+ EvilEvents::BootPoint[:event_system].resolve_event_object(
33
33
  event_type, symbolized_event_payload(event_payload)
34
34
  )
35
35
  end
@@ -34,7 +34,7 @@ class EvilEvents::Core::Events::Serializers
34
34
  raise DeserializationError
35
35
  end
36
36
 
37
- EvilEvents::BootPoint::System[:event_system].resolve_event_object(event_type, event_payload)
37
+ EvilEvents::BootPoint[:event_system].resolve_event_object(event_type, event_payload)
38
38
  end
39
39
  end
40
40
 
@@ -17,9 +17,9 @@ class EvilEvents::Core::Events::Subscriber
17
17
  def subscribe_to(event_type, delegator: nil)
18
18
  case event_type
19
19
  when Class
20
- EvilEvents::BootPoint::System[:event_system].observe(event_type, self, delegator)
20
+ EvilEvents::BootPoint[:event_system].observe(event_type, self, delegator)
21
21
  when String
22
- EvilEvents::BootPoint::System[:event_system].raw_observe(event_type, self, delegator)
22
+ EvilEvents::BootPoint[:event_system].raw_observe(event_type, self, delegator)
23
23
  else
24
24
  raise IncompatibleEventAttrTypeError
25
25
  end
@@ -13,7 +13,7 @@ module EvilEvents::Core::Events
13
13
  # @param delegator_resolver [EvilEvents::Shared::DelegatorResolver]
14
14
  #
15
15
  # @since 0.1.0
16
- def initialize(subscriber, delegator_resolver)
16
+ def initialize(subscriber, delegator_resolver = default_resolver)
17
17
  @subscriber = subscriber
18
18
  @delegator_resolver = delegator_resolver
19
19
  end
@@ -39,5 +39,15 @@ module EvilEvents::Core::Events
39
39
  def delegator
40
40
  @delegator ||= delegator_resolver.delegator
41
41
  end
42
+
43
+ private
44
+
45
+ # @return [EvilEvents::Shared::DelegatorResolver]
46
+ #
47
+ # @since 0.1.0
48
+ def default_resolver
49
+ delegation = -> { EvilEvents::BootPoint[:config].subscriber.default_delegator }
50
+ EvilEvents::Shared::DelegatorResolver.new(delegation)
51
+ end
42
52
  end
43
53
  end
@@ -13,6 +13,7 @@ module EvilEvents::Core
13
13
  require_relative 'events/event_extensions/adapter_customizable'
14
14
  require_relative 'events/event_extensions/observable'
15
15
  require_relative 'events/event_extensions/serializable'
16
+ require_relative 'events/event_extensions/emittable'
16
17
  require_relative 'events/abstract_event'
17
18
  require_relative 'events/manager'
18
19
  require_relative 'events/manager/subscriber_list'
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EvilEvents
4
+ # @api private
4
5
  # @since 0.1.0
5
6
  module Core
6
7
  require_relative 'core/activity_logging'
@@ -81,6 +81,8 @@ module EvilEvents
81
81
  __outer_context__.public_send(method_name, *arguments, &block)
82
82
  when __required_context__.respond_to?(method_name)
83
83
  __required_context__.public_send(method_name, *arguments, &block)
84
+ when ::Kernel.respond_to?(method_name)
85
+ ::Kernel.public_send(method_name, *arguments, &block)
84
86
  else
85
87
  super
86
88
  end
@@ -7,7 +7,7 @@ module EvilEvents::Shared
7
7
  # @since 0.1.0
8
8
  def initialize(*, **)
9
9
  super
10
- self.level = :info
10
+ self.level = ::Logger::INFO
11
11
  end
12
12
  end
13
13
  end
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EvilEvents
4
+ # @api public
4
5
  # @since 0.1.0
5
6
  module Shared
6
- require_relative 'shared/mockable_class_builder'
7
+ require_relative 'shared/types'
7
8
  require_relative 'shared/logger'
8
- require_relative 'shared/configurable'
9
- require_relative 'shared/dependency_container'
10
9
  require_relative 'shared/structure'
11
- require_relative 'shared/types'
10
+ require_relative 'shared/configurable'
12
11
  require_relative 'shared/combined_context'
13
- require_relative 'shared/combined_context_mixin'
14
12
  require_relative 'shared/delegator_resolver'
13
+ require_relative 'shared/dependency_container'
14
+ require_relative 'shared/mockable_class_builder'
15
+ require_relative 'shared/combined_context_mixin'
15
16
  end
16
17
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EvilEvents::System
4
+ # @api private
5
+ # @since 0.1.0
6
+ class Broadcaster
7
+ # @return [EvilEvents::Core::Broadcasting::Emitter]
8
+ #
9
+ # @since 0.1.0
10
+ attr_reader :event_emitter
11
+
12
+ # @since 0.1.0
13
+ def initialize
14
+ @event_emitter = EvilEvents::Core::Broadcasting::Emitter.new
15
+ end
16
+
17
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
18
+ # @return void
19
+ #
20
+ # @since 0.1.0
21
+ def emit(event)
22
+ event_emitter.emit(event)
23
+ end
24
+
25
+ # @param event_type [String]
26
+ # @param event_attributes [Hash]
27
+ # @return void
28
+ #
29
+ # @since 0.1.0
30
+ def raw_emit(event_type, **event_attributes)
31
+ event_emitter.raw_emit(event_type, **event_attributes)
32
+ end
33
+
34
+ # @param adapter_name [Symbol, String]
35
+ # @return [EvilEvents::Core::Broadcasting::Dispatcher::Dispatchable]
36
+ #
37
+ # @since 0.1.0
38
+ def resolve_adapter(adapter_name)
39
+ EvilEvents::Core::Broadcasting::Adapters.resolve(adapter_name)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EvilEvents::System
4
+ # @api private
5
+ # @since 0.1.0
6
+ module EventBuilder
7
+ class << self
8
+ # @param event_type [String]
9
+ # @param event_class_definitions [Proc]
10
+ # @return [Class{EvilEvents::Core::Events::AbstractEvent}]
11
+ #
12
+ # @since 0.1.0
13
+ def define_event_class(event_type, &event_class_definitions)
14
+ EvilEvents::Core::Events::EventClassFactory.create(
15
+ event_type, &event_class_definitions
16
+ )
17
+ end
18
+
19
+ # @param event_type [String]
20
+ # @return [Class{EvilEvents::Core::Events::AbstractEvent}]
21
+ #
22
+ # @since 0.1.0
23
+ def define_abstract_event_class(event_type)
24
+ EvilEvents::Core::Events::EventClassFactory.create_abstract(
25
+ event_type
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EvilEvents::System
4
+ # @api private
5
+ # @since 0.1.0
6
+ class EventManager
7
+ # @return [EvilEvents::Core::Events::ManagerRegistry]
8
+ #
9
+ # @since 0.1.0
10
+ attr_reader :manager_registry
11
+
12
+ def initialize
13
+ @manager_registry = EvilEvents::Core::Events::ManagerRegistry.new
14
+ end
15
+
16
+ # @param event_class [Class{Evilevents::Core::Events::AbstractEvent}]
17
+ # @param raw_subscriber [Object]
18
+ # @param delegator [String, Symbol, NilClass]
19
+ # @return void
20
+ #
21
+ # @since 0.1.0
22
+ def observe(event_class, raw_subscriber, delegator)
23
+ manager_registry.manager_of_event(event_class)
24
+ .observe(raw_subscriber, delegator)
25
+ end
26
+
27
+ # @param event_type [String, Symbol]
28
+ # @param raw_subscriber [Object]
29
+ # @param delegator [String, Symbol, NilClass]
30
+ # @return void
31
+ #
32
+ # @since 0.1.0
33
+ def raw_observe(event_type, raw_subscriber, delegator)
34
+ manager_registry.manager_of_event_type(event_type)
35
+ .observe(raw_subscriber, delegator)
36
+ end
37
+
38
+ # @param event_class [Class{EvilEvents::Core::Events::AbstractEvent}]
39
+ # @return [Array<EvilEvents::Core::Events::Subscriber>]
40
+ #
41
+ # @since 0.1.0
42
+ def observers(event_class)
43
+ manager_registry.manager_of_event(event_class).subscribers
44
+ end
45
+
46
+ # @param event_class [Class{EvilEvents::Core::Events::AbstractEvent}]
47
+ # @return void
48
+ #
49
+ # @since 0.1.0
50
+ def register_event_class(event_class)
51
+ manager_registry.register_with(event_class)
52
+ end
53
+
54
+ # @param event_class [Class{EvilEvents::Core::events::AbstractEvent}]
55
+ # @return void
56
+ #
57
+ # @since 0.1.0
58
+ def unregister_event_class(event_class)
59
+ manager_registry.unregister_with(event_class)
60
+ end
61
+
62
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
63
+ # @return [EvilEvents::Core::Events::Manager]
64
+ #
65
+ # @since 0.1.0
66
+ def manager_of_event(event)
67
+ manager_registry.manager_of_event(event.class)
68
+ end
69
+
70
+ # @param event_type [String]
71
+ # @return [EvilEvents::Core::Events::Manager]
72
+ #
73
+ # @since 0.1.0
74
+ def manager_of_event_type(event_type)
75
+ manager_registry.manager_of_event_type(event_type)
76
+ end
77
+
78
+ # @param event_type [String]
79
+ # @param event_attributes [Hash]
80
+ # @return [EvilEvents::Core::Events::AbstractEvent]
81
+ #
82
+ # @since 0.1.0
83
+ def resolve_event_object(event_type, **event_attributes)
84
+ manager_of_event_type(event_type).event_class.new(**event_attributes)
85
+ end
86
+
87
+ # @param event_class [EvilEvents::Core::Events::AbstractEvent]
88
+ # @return [Boolean]
89
+ #
90
+ # @since 0.1.0
91
+ def managed_event?(event_class)
92
+ manager_registry.managed_event?(event_class)
93
+ end
94
+ end
95
+ end
@@ -9,11 +9,11 @@ class EvilEvents::System
9
9
  class Mock
10
10
  # @see EvilEvents::System
11
11
  # @since 0.1.0
12
- attr_reader :event_emitter
12
+ attr_reader :broadcaster
13
13
 
14
14
  # @see EvilEvents::System
15
15
  # @since 0.1.0
16
- attr_reader :manager_registry
16
+ attr_reader :event_manager
17
17
 
18
18
  # @see EvilEvents::System
19
19
  # @since 0.1.0
@@ -49,7 +49,7 @@ class EvilEvents::System
49
49
 
50
50
  # @see EvilEvents::System
51
51
  # @since 0.1.0
52
- def manager_of(event); end
52
+ def manager_of_event(event); end
53
53
 
54
54
  # @see EvilEvents::System
55
55
  # @since 0.1.0
@@ -66,5 +66,9 @@ class EvilEvents::System
66
66
  # @see EvilEvents::System
67
67
  # @since 0.1.0
68
68
  def define_abstract_event_class(event_type); end
69
+
70
+ # @see EvilEvents::System
71
+ # @since 0.1.0
72
+ def managed_event?(event_class); end
69
73
  end
70
74
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EvilEvents::System
4
+ # @api private
5
+ # @since 0.1.0
6
+ module Mocking
7
+ class << self
8
+ # @param base_class [EvilEvents::System]
9
+ #
10
+ # @since 0.1.0
11
+ def included(base_class)
12
+ base_class.extend(ClassMethods)
13
+ end
14
+ end
15
+
16
+ # @since 0.1.0
17
+ module ClassMethods
18
+ # @return [EvilEvents::System::Mock]
19
+ #
20
+ # @since 0.1.0
21
+ def build_mock
22
+ Mock.new
23
+ end
24
+
25
+ # @return [EvilEvents::System]
26
+ #
27
+ # @since 0.1.0
28
+ def build_stub
29
+ new
30
+ end
31
+ end
32
+ end
33
+ end
@@ -3,147 +3,56 @@
3
3
  # @api private
4
4
  # @since 0.1.0
5
5
  class EvilEvents::System
6
- class << self
7
- # @return [EvilEvents::System::Mock]
8
- #
9
- # @since 0.1.0
10
- def build_mock
11
- Mock.new
12
- end
13
-
14
- # @return [EvilEvents::System]
15
- #
16
- # @since 0.1.0
17
- def build_stub
18
- new
19
- end
20
- end
6
+ require_relative 'system/mock'
7
+ require_relative 'system/mocking'
8
+ require_relative 'system/broadcaster'
9
+ require_relative 'system/event_builder'
10
+ require_relative 'system/event_manager'
21
11
 
22
12
  # @since 0.1.0
23
- attr_reader :event_emitter
24
-
13
+ extend Forwardable
25
14
  # @since 0.1.0
26
- attr_reader :manager_registry
15
+ include Mocking
27
16
 
17
+ # @see EvilEvents::System::Broadcaster
28
18
  # @since 0.1.0
29
- def initialize
30
- @manager_registry = EvilEvents::Core::Events::ManagerRegistry.new
31
- @event_emitter = EvilEvents::Core::Broadcasting::Emitter.new
32
- end
19
+ def_delegators :broadcaster,
20
+ :emit,
21
+ :raw_emit,
22
+ :resolve_adapter
33
23
 
34
- # @param event_class [Class{Evilevents::Core::Events::AbstractEvent}]
35
- # @param raw_subscriber [Object]
36
- # @param delegator [String, Symbol, NilClass]
37
- # @return void
38
- #
24
+ # @see EvilEvents::System::EventManager
39
25
  # @since 0.1.0
40
- def observe(event_class, raw_subscriber, delegator)
41
- manager_registry.manager_of_event(event_class)
42
- .observe(raw_subscriber, delegator)
43
- end
26
+ def_delegators :event_manager,
27
+ :observe,
28
+ :raw_observe,
29
+ :observers,
30
+ :register_event_class,
31
+ :unregister_event_class,
32
+ :manager_of_event,
33
+ :manager_of_event_type,
34
+ :resolve_event_object,
35
+ :managed_event?
44
36
 
45
- # @param event_type [String, Symbol]
46
- # @param raw_subscriber [Object]
47
- # @param delegator [String, Symbol, NilClass]
48
- # @return void
49
- #
37
+ # @see EvilEvents::System::EventBuilder
50
38
  # @since 0.1.0
51
- def raw_observe(event_type, raw_subscriber, delegator)
52
- manager_registry.manager_of_event_type(event_type)
53
- .observe(raw_subscriber, delegator)
54
- end
39
+ def_delegators 'EvilEvents::System::EventBuilder',
40
+ :define_event_class,
41
+ :define_abstract_event_class
55
42
 
56
- # @param event_class [Class{EvilEvents::Core::Events::AbstractEvent}]
57
- # @return [Array<EvilEvents::Core::Events::Subscriber>]
43
+ # @return [EvilEvents::System::Broadcaster]
58
44
  #
59
45
  # @since 0.1.0
60
- def observers(event_class)
61
- manager_registry.manager_of_event(event_class).subscribers
62
- end
46
+ attr_reader :broadcaster
63
47
 
64
- # @param event [EvilEvents::Core::Events::AbstractEvent]
65
- # @return void
48
+ # @return [EvilEvents::System::EventManager]
66
49
  #
67
50
  # @since 0.1.0
68
- def emit(event)
69
- event_emitter.emit(event)
70
- end
51
+ attr_reader :event_manager
71
52
 
72
- # @param event_type [String]
73
- # @param event_attributes [Hash]
74
- # @return void
75
- #
76
53
  # @since 0.1.0
77
- def raw_emit(event_type, **event_attributes)
78
- event_emitter.raw_emit(event_type, **event_attributes)
79
- end
80
-
81
- # @param adapter_name [Symbol, String]
82
- # @return [EvilEvents::Core::Broadcasting::Dispatcher::Dispatchable]
83
- #
84
- # @since 0.1.0
85
- def resolve_adapter(adapter_name)
86
- EvilEvents::Core::Broadcasting::Adapters.resolve(adapter_name)
87
- end
88
-
89
- # @param event_class [Class{EvilEvents::Core::Events::AbstractEvent}]
90
- # @return void
91
- #
92
- # @since 0.1.0
93
- def register_event_class(event_class)
94
- manager_registry.register_with(event_class)
95
- end
96
-
97
- # @param event_class [Class{EvilEvents::Core::events::AbstractEvent}]
98
- # @return void
99
- #
100
- # @since 0.1.0
101
- def unregister_event_class(event_class)
102
- manager_registry.unregister_with(event_class)
103
- end
104
-
105
- # @param event [EvilEvents::Core::Events::AbstractEvent]
106
- # @return [EvilEvents::Core::Events::Manager]
107
- #
108
- # @since 0.1.0
109
- def manager_of_event(event)
110
- manager_registry.manager_of_event(event.class)
111
- end
112
-
113
- # @param event_type [String]
114
- # @return [EvilEvents::Core::Events::Manager]
115
- #
116
- # @since 0.1.0
117
- def manager_of_event_type(event_type)
118
- manager_registry.manager_of_event_type(event_type)
119
- end
120
-
121
- # @param event_type [String]
122
- # @param event_attributes [Hash]
123
- # @return [EvilEvents::Core::Events::AbstractEvent]
124
- #
125
- # @since 0.1.0
126
- def resolve_event_object(event_type, **event_attributes)
127
- manager_of_event_type(event_type).event_class.new(**event_attributes)
128
- end
129
-
130
- # @param event_class_definitions [Proc]
131
- # @return [Class{EvilEvents::Core::Events::AbstractEvent}]
132
- #
133
- # @since 0.1.0
134
- def define_event_class(event_type, &event_class_definitions)
135
- EvilEvents::Core::Events::EventClassFactory.create(
136
- event_type, &event_class_definitions
137
- )
138
- end
139
-
140
- # @param event_type [String]
141
- # @return [Class{EvilEvents::Core::Events::AbstractEvent}]
142
- #
143
- # @since 0.1.0
144
- def define_abstract_event_class(event_type)
145
- EvilEvents::Core::Events::EventClassFactory.create_abstract(
146
- event_type
147
- )
54
+ def initialize
55
+ @broadcaster = Broadcaster.new
56
+ @event_manager = EventManager.new
148
57
  end
149
58
  end
@@ -3,5 +3,5 @@
3
3
  module EvilEvents
4
4
  # @api public
5
5
  # @since 0.1.0
6
- VERSION = '0.1.0rc1'
6
+ VERSION = '0.1.0rc2'
7
7
  end
data/lib/evil_events.rb CHANGED
@@ -4,7 +4,8 @@ require 'dry-configurable'
4
4
  require 'dry-container'
5
5
  require 'dry-struct'
6
6
  require 'dry-types'
7
- require 'concurrent'
7
+ require 'concurrent/array'
8
+ require 'concurrent/map'
8
9
  require 'logger'
9
10
  require 'json'
10
11
 
@@ -14,7 +15,6 @@ module EvilEvents
14
15
  require_relative 'evil_events/shared'
15
16
  require_relative 'evil_events/core'
16
17
  require_relative 'evil_events/system'
17
- require_relative 'evil_events/system/mock'
18
18
  require_relative 'evil_events/config'
19
19
  require_relative 'evil_events/boot_point'
20
20
  require_relative 'evil_events/version'
@@ -27,7 +27,7 @@ module EvilEvents
27
27
  # @api public
28
28
  # @since 0.1.0
29
29
  def [](event_type)
30
- EvilEvents::BootPoint::System[:event_system].define_abstract_event_class(
30
+ EvilEvents::BootPoint[:event_system].define_abstract_event_class(
31
31
  event_type
32
32
  )
33
33
  end
@@ -36,7 +36,7 @@ module EvilEvents
36
36
  # @api public
37
37
  # @since 0.1.0
38
38
  def define_event(event_type, &event_class_definitions)
39
- EvilEvents::BootPoint::System[:event_system].define_event_class(
39
+ EvilEvents::BootPoint[:event_system].define_event_class(
40
40
  event_type, &event_class_definitions
41
41
  )
42
42
  end
@@ -45,7 +45,7 @@ module EvilEvents
45
45
  # @api public
46
46
  # @since 0.1.0
47
47
  def emit(event_type, **event_attributes)
48
- EvilEvents::BootPoint::System[:event_system].raw_emit(
48
+ EvilEvents::BootPoint[:event_system].raw_emit(
49
49
  event_type, **event_attributes
50
50
  )
51
51
  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.0rc1
4
+ version: 0.1.0rc2
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-01 00:00:00.000000000 Z
11
+ date: 2017-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-types
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.0.5
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.7.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.7.2
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: pry
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,20 @@ dependencies:
108
122
  - - '='
109
123
  - !ruby/object:Gem::Version
110
124
  version: 0.15.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov-json
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: '0.2'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: '0.2'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: rubocop
113
141
  requirement: !ruby/object:Gem::Requirement
@@ -190,6 +218,7 @@ files:
190
218
  - ".rubocop.yml"
191
219
  - ".travis.yml"
192
220
  - ".yardopts"
221
+ - CHANGELOG.md
193
222
  - CODE_OF_CONDUCT.md
194
223
  - Gemfile
195
224
  - LICENSE.txt
@@ -208,12 +237,13 @@ files:
208
237
  - lib/evil_events/core/broadcasting/adapters/memory_async.rb
209
238
  - lib/evil_events/core/broadcasting/adapters/memory_sync.rb
210
239
  - lib/evil_events/core/broadcasting/dispatcher.rb
211
- - lib/evil_events/core/broadcasting/dispatcher/dispatchable.rb
240
+ - lib/evil_events/core/broadcasting/dispatcher/mixin.rb
212
241
  - lib/evil_events/core/broadcasting/emitter.rb
213
242
  - lib/evil_events/core/events.rb
214
243
  - lib/evil_events/core/events/abstract_event.rb
215
244
  - lib/evil_events/core/events/event_class_factory.rb
216
245
  - lib/evil_events/core/events/event_extensions/adapter_customizable.rb
246
+ - lib/evil_events/core/events/event_extensions/emittable.rb
217
247
  - lib/evil_events/core/events/event_extensions/manageable.rb
218
248
  - lib/evil_events/core/events/event_extensions/observable.rb
219
249
  - lib/evil_events/core/events/event_extensions/payloadable.rb
@@ -240,7 +270,11 @@ files:
240
270
  - lib/evil_events/shared/structure.rb
241
271
  - lib/evil_events/shared/types.rb
242
272
  - lib/evil_events/system.rb
273
+ - lib/evil_events/system/broadcaster.rb
274
+ - lib/evil_events/system/event_builder.rb
275
+ - lib/evil_events/system/event_manager.rb
243
276
  - lib/evil_events/system/mock.rb
277
+ - lib/evil_events/system/mocking.rb
244
278
  - lib/evil_events/version.rb
245
279
  homepage: https://github.com/ergosploit/evil_events
246
280
  licenses: