evil_events 0.1.0rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +84 -0
  5. data/.travis.yml +10 -0
  6. data/.yardopts +1 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +17 -0
  11. data/Rakefile +6 -0
  12. data/bin/console +12 -0
  13. data/bin/setup +8 -0
  14. data/evil_events.gemspec +42 -0
  15. data/lib/evil_events/boot_point.rb +17 -0
  16. data/lib/evil_events/config.rb +30 -0
  17. data/lib/evil_events/core/activity_logging.rb +24 -0
  18. data/lib/evil_events/core/broadcasting/adapters/memory_async.rb +20 -0
  19. data/lib/evil_events/core/broadcasting/adapters/memory_sync.rb +20 -0
  20. data/lib/evil_events/core/broadcasting/adapters.rb +11 -0
  21. data/lib/evil_events/core/broadcasting/dispatcher/dispatchable.rb +17 -0
  22. data/lib/evil_events/core/broadcasting/dispatcher.rb +17 -0
  23. data/lib/evil_events/core/broadcasting/emitter.rb +45 -0
  24. data/lib/evil_events/core/broadcasting.rb +13 -0
  25. data/lib/evil_events/core/events/abstract_event.rb +44 -0
  26. data/lib/evil_events/core/events/event_class_factory.rb +54 -0
  27. data/lib/evil_events/core/events/event_extensions/adapter_customizable.rb +49 -0
  28. data/lib/evil_events/core/events/event_extensions/manageable.rb +26 -0
  29. data/lib/evil_events/core/events/event_extensions/observable.rb +49 -0
  30. data/lib/evil_events/core/events/event_extensions/payloadable/abstract_payload.rb +24 -0
  31. data/lib/evil_events/core/events/event_extensions/payloadable.rb +52 -0
  32. data/lib/evil_events/core/events/event_extensions/serializable.rb +21 -0
  33. data/lib/evil_events/core/events/event_extensions/type_aliasing.rb +87 -0
  34. data/lib/evil_events/core/events/manager/subscriber_list.rb +30 -0
  35. data/lib/evil_events/core/events/manager.rb +78 -0
  36. data/lib/evil_events/core/events/manager_factory.rb +17 -0
  37. data/lib/evil_events/core/events/manager_registry.rb +141 -0
  38. data/lib/evil_events/core/events/serializers/hash.rb +51 -0
  39. data/lib/evil_events/core/events/serializers/json.rb +43 -0
  40. data/lib/evil_events/core/events/serializers.rb +16 -0
  41. data/lib/evil_events/core/events/subscriber/mixin.rb +28 -0
  42. data/lib/evil_events/core/events/subscriber.rb +43 -0
  43. data/lib/evil_events/core/events.rb +25 -0
  44. data/lib/evil_events/core.rb +10 -0
  45. data/lib/evil_events/shared/combined_context.rb +113 -0
  46. data/lib/evil_events/shared/combined_context_mixin.rb +43 -0
  47. data/lib/evil_events/shared/configurable.rb +7 -0
  48. data/lib/evil_events/shared/delegator_resolver.rb +36 -0
  49. data/lib/evil_events/shared/dependency_container.rb +7 -0
  50. data/lib/evil_events/shared/logger.rb +13 -0
  51. data/lib/evil_events/shared/mockable_class_builder.rb +27 -0
  52. data/lib/evil_events/shared/structure.rb +7 -0
  53. data/lib/evil_events/shared/types.rb +9 -0
  54. data/lib/evil_events/shared.rb +16 -0
  55. data/lib/evil_events/system/mock.rb +70 -0
  56. data/lib/evil_events/system.rb +149 -0
  57. data/lib/evil_events/version.rb +7 -0
  58. data/lib/evil_events.rb +53 -0
  59. metadata +269 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8d92142f28955faa9a09b89fd4e49d90ee6d916c
4
+ data.tar.gz: 8e1db3af52fabe05fe15328f6fe096d7cca34f4c
5
+ SHA512:
6
+ metadata.gz: ba2407d8d151584caee50926f92bc7ffa766dc996ba79f8a7c6c175edc83296e9bb3a83ba49621afe13122c0fd0bd4c86015070e5bd9ed8e66d327e5ea362268
7
+ data.tar.gz: afc02be9c2ffc74d5b02e5bb8c7ccfb420e3fd13efc9838df62257ee6504ca562a051af252b1a33c2a3e568fbda79a3d45b9c375e9438ab52728688c248409d5
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .rspec_status
11
+ .DS_Store
12
+ .idea
13
+ /.gtm/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=progress
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,84 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ DisplayCopNames: true
5
+ DisplayStyleGuide: true
6
+ TargetRubyVersion: 2.3
7
+ Include:
8
+ - lib/**/*
9
+ - spec/**/*
10
+ Exclude:
11
+ - Gemfile
12
+ - Rakefile
13
+ - evil_events.gemspec
14
+
15
+ Style/SingleLineMethods:
16
+ Exclude:
17
+ - spec/**/*
18
+
19
+ Style/AsciiComments:
20
+ Enabled: false
21
+
22
+ Style/Alias:
23
+ Enabled: false
24
+
25
+ Style/GuardClause:
26
+ Enabled: false
27
+
28
+ Style/Documentation:
29
+ Enabled: false
30
+
31
+ Style/ClassAndModuleChildren:
32
+ Enabled: false
33
+
34
+ Style/EmptyCaseCondition:
35
+ Enabled: false
36
+
37
+ Style/FrozenStringLiteralComment:
38
+ Enabled: true
39
+
40
+ Style/ParallelAssignment:
41
+ Enabled: false
42
+
43
+ Naming/FileName:
44
+ Enabled: false
45
+
46
+ Naming/VariableNumber:
47
+ EnforcedStyle: snake_case
48
+
49
+ Metrics/LineLength:
50
+ Max: 100
51
+
52
+ Metrics/BlockLength:
53
+ Exclude:
54
+ - spec/**/*
55
+
56
+ Metrics/CyclomaticComplexity:
57
+ Max: 7
58
+
59
+ Metrics/MethodLength:
60
+ Max: 25
61
+
62
+ RSpec/HookArgument:
63
+ Enabled: false
64
+
65
+ RSpec/NestedGroups:
66
+ Max: 5
67
+
68
+ RSpec/MessageSpies:
69
+ Enabled: false
70
+
71
+ RSpec/ExampleLength:
72
+ Enabled: false
73
+
74
+ RSpec/MultipleExpectations:
75
+ Enabled: false
76
+
77
+ RSpec/DescribeClass:
78
+ Enabled: false
79
+
80
+ RSpec/LetSetup:
81
+ Enabled: false
82
+
83
+ RSpec/AnyInstance:
84
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.5
4
+ - 2.4.2
5
+ - 2.2.7
6
+ - ruby-head
7
+ - jruby-head
8
+
9
+ sudo: false
10
+ before_install: gem install bundler -v 1.15.3
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --protected --private --markup markdown
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at iamdaiver@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in evil_events.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Rustam Ibragimov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # EvilEvents - powerful event system for ruby applications
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/evil_events.svg)](https://badge.fury.io/rb/evil_events)
4
+
5
+ Note: work in progress!
6
+
7
+ ### TODO
8
+ - Full test coverage (0.1.0)
9
+ - Basic documentation (README) (0.1.0)
10
+ - FULL documentation (0.2.1)
11
+ - Notifier abstraction (0.2.0)
12
+ - Event sourcing (0.3.0)
13
+ - RSpec matchers (separated gem)
14
+ - metadata field (0.1.0)
15
+ - Concrete error messages for exceptions (0.1.0)
16
+ - Event emition hooks (0.2.0)
17
+ - Event emition scheduling (0.2.0)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'evil_events'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ require 'pry'
12
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,42 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'evil_events/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.required_ruby_version = '>= 2.2.7'
9
+
10
+ spec.name = 'evil_events'
11
+ spec.version = EvilEvents::VERSION
12
+ spec.authors = 'Rustam Ibragimov'
13
+ spec.email = 'iamdaiver@icloud.com'
14
+ spec.homepage = 'https://github.com/ergosploit/evil_events'
15
+ spec.license = 'MIT'
16
+ spec.summary = 'Event subsystem for any ruby application'
17
+ spec.description = 'Flexible and fully customizable event subsystem for ruby applications' \
18
+ 'with a wide set of customization interfaces and ' \
19
+ 'powerful event definition DSL'
20
+
21
+ spec.bindir = 'bin'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(spec|features)/})
27
+ end
28
+
29
+ spec.add_dependency 'dry-types', '0.12.0'
30
+ spec.add_dependency 'dry-struct', '0.3.1'
31
+ spec.add_dependency 'dry-configurable', '0.7.0'
32
+ spec.add_dependency 'dry-container', '0.6.0'
33
+ spec.add_dependency 'concurrent-ruby', '1.0.5'
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'
42
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents
4
+ # @api private
5
+ # @since 0.1.0
6
+ module BootPoint
7
+ # @api private
8
+ # @since 0.1.0
9
+ class System
10
+ # @since 0.1.0
11
+ extend Shared::DependencyContainer::Mixin
12
+
13
+ register(:event_system, memoize: true) { EvilEvents::System.new }
14
+ register(:config) { EvilEvents::Config }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents
4
+ # @api public
5
+ # @since 0.1.0
6
+ Config = EvilEvents::Shared::MockableClassBuilder.new_class do
7
+ extend EvilEvents::Shared::Configurable
8
+
9
+ class << self
10
+ # @return void
11
+ #
12
+ # @since 0.1.0
13
+ def reset!
14
+ config.adapter.default = :memory_sync
15
+ config.subscriber.default_delegator = :call
16
+ config.logger = EvilEvents::Shared::Logger.new(STDOUT)
17
+ end
18
+ end
19
+
20
+ setting :adapter, reader: true do
21
+ setting :default, :memory_sync
22
+ end
23
+
24
+ setting :subscriber, reader: true do
25
+ setting :default_delegator, :call
26
+ end
27
+
28
+ setting :logger, EvilEvents::Shared::Logger.new(STDOUT), reader: true
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core
4
+ # @api private
5
+ # @since 0.1.0
6
+ module ActivityLogging
7
+ # @param activity [String, NilClass]
8
+ # @param message [String, NilClass]
9
+ # @return void
10
+ #
11
+ # @since 0.1.0
12
+ def log_activity(activity = nil, message = nil)
13
+ progname = "[EvilEvents:#{activity}]"
14
+ activity_logger.add(activity_logger.level, message, progname)
15
+ end
16
+
17
+ # @return [Logger]
18
+ #
19
+ # @since 0.1.0
20
+ def activity_logger
21
+ EvilEvents::BootPoint::System[:config].logger
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Broadcasting
4
+ class Adapters
5
+ # @api public
6
+ # @since 0.1.0
7
+ class MemoryAsync
8
+ # @since 0.1.0
9
+ include Dispatcher::Dispatchable
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) }
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Broadcasting
4
+ class Adapters
5
+ # @api public
6
+ # @since 0.1.0
7
+ class MemorySync
8
+ # @since 0.1.0
9
+ include Dispatcher::Dispatchable
10
+
11
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
12
+ # @return void
13
+ #
14
+ # @since 0.1.0
15
+ def call(event)
16
+ dispatch(event)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Broadcasting
4
+ # @since 0.1.0
5
+ class Adapters
6
+ extend EvilEvents::Shared::DependencyContainer::Mixin
7
+
8
+ register :memory_sync, -> { Adapters::MemorySync.new }
9
+ register :memory_async, -> { Adapters::MemoryAsync.new }
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Broadcasting
4
+ class Dispatcher
5
+ # @api public
6
+ # @since 0.1.0
7
+ module Dispatchable
8
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
9
+ # @return void
10
+ #
11
+ # @since 0.1.0
12
+ def dispatch(event)
13
+ Dispatcher.dispatch(event)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Broadcasting
4
+ # @api private
5
+ # @since 0.1.0
6
+ class Dispatcher # Broadcaster
7
+ class << self
8
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
9
+ # @return void
10
+ #
11
+ # @since 0.1.0
12
+ def dispatch(event) # Broadcast
13
+ EvilEvents::BootPoint::System[:event_system].manager_of_event(event).notify(event)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Broadcasting
4
+ # @api private
5
+ # @since 0.1.0
6
+ class Emitter
7
+ # @since 0.1.0
8
+ include EvilEvents::Core::ActivityLogging
9
+
10
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
11
+ # @return void
12
+ #
13
+ # @since 0.1.0
14
+ def emit(event)
15
+ log_emitter_activity(event)
16
+ event.adapter.call(event)
17
+ end
18
+
19
+ # @param event_type [String]
20
+ # @param event_attributes [Hash]
21
+ # @return void
22
+ #
23
+ # @since 0.1.0
24
+ def raw_emit(event_type, **event_attributes)
25
+ event_object = EvilEvents::BootPoint::System[:event_system].resolve_event_object(
26
+ event_type,
27
+ **event_attributes
28
+ )
29
+
30
+ emit(event_object)
31
+ end
32
+
33
+ private
34
+
35
+ # @param event [EvilEvents::Core::Events::AbstractEvent]
36
+ # @return void
37
+ #
38
+ # @since 0.1.0
39
+ def log_emitter_activity(event)
40
+ activity = "EventEmitted(#{event.adapter_name})"
41
+ message = "Type: #{event.type} :: Payload: #{event.payload}"
42
+ log_activity(activity, message)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core
4
+ # @since 0.1.0
5
+ module Broadcasting
6
+ require_relative 'broadcasting/dispatcher'
7
+ require_relative 'broadcasting/dispatcher/dispatchable'
8
+ require_relative 'broadcasting/adapters'
9
+ require_relative 'broadcasting/adapters/memory_sync'
10
+ require_relative 'broadcasting/adapters/memory_async'
11
+ require_relative 'broadcasting/emitter'
12
+ end
13
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Events
4
+ # @abstract
5
+ # @api private
6
+ # @since 0.1.0
7
+ class AbstractEvent
8
+ # @since 0.1.0
9
+ include EventExtensions::TypeAliasing
10
+ # @since 0.1.0
11
+ include EventExtensions::Payloadable
12
+ # @since 0.1.0
13
+ include EventExtensions::Manageable
14
+ # @since 0.1.0
15
+ include EventExtensions::Observable
16
+ # @since 0.1.0
17
+ include EventExtensions::AdapterCustomizable
18
+ # @since 0.1.0
19
+ include EventExtensions::Serializable
20
+ # @since 0.1.0
21
+ extend EvilEvents::Shared::CombinedContextMixin
22
+
23
+ # @param payload_attributes [Hash]
24
+ #
25
+ # @since 0.1.0
26
+ def initialize(**payload_attributes)
27
+ @payload = payload_class.new(**payload_attributes)
28
+ end
29
+
30
+ # @return [Hash]
31
+ #
32
+ # @since 0.1.0
33
+ def payload
34
+ @payload.to_h
35
+ end
36
+
37
+ # @return void
38
+ #
39
+ # @since 0.1.0
40
+ def emit
41
+ EvilEvents::BootPoint::System[:event_system].emit(self)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EvilEvents::Core::Events
4
+ # @api private
5
+ # @since 0.1.0
6
+ module EventClassFactory
7
+ class << self
8
+ # @param event_type [String]
9
+ # @raise [EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError]
10
+ # @return [AbstractEvent]
11
+ #
12
+ # @since 0.1.0
13
+ def create_abstract(event_type)
14
+ Class.new(AbstractEvent).tap do |klass|
15
+ klass.type(event_type)
16
+
17
+ class << klass
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
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ # @param event_type [String]
34
+ # @param event_class_definitions [Proc]
35
+ # @yield [AbstractEvent]
36
+ # @raise [EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError]
37
+ # @return [AbstractEvent]
38
+ #
39
+ # @since 0.1.0
40
+ def create(event_type, &event_class_definitions)
41
+ Class.new(AbstractEvent).tap do |klass|
42
+ begin
43
+ klass.type(event_type)
44
+ klass.manage!
45
+ klass.evaluate(&event_class_definitions) if block_given?
46
+ rescue EvilEvents::Core::Events::ManagerRegistry::AlreadyManagedEventClassError
47
+ EvilEvents::BootPoint::System[:event_system].unregister_event_class(klass)
48
+ raise
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end