evil_events 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +10 -1
- data/.travis.yml +4 -5
- data/CHANGELOG.md +73 -0
- data/evil_events.gemspec +6 -3
- data/lib/evil_events.rb +3 -0
- data/lib/evil_events/core/broadcasting.rb +1 -0
- data/lib/evil_events/core/broadcasting/emitter.rb +19 -13
- data/lib/evil_events/core/broadcasting/emitter/adapter_proxy.rb +46 -0
- data/lib/evil_events/core/config.rb +37 -40
- data/lib/evil_events/core/events.rb +34 -3
- data/lib/evil_events/core/events/abstract_event.rb +4 -6
- data/lib/evil_events/core/events/event_extensions/class_signature.rb +13 -0
- data/lib/evil_events/core/events/event_extensions/class_signature/equalizer.rb +0 -2
- data/lib/evil_events/core/events/event_extensions/dispatchable.rb +74 -0
- data/lib/evil_events/core/events/event_extensions/observable.rb +2 -0
- data/lib/evil_events/core/events/event_extensions/serializable.rb +22 -2
- data/lib/evil_events/core/events/manager.rb +1 -1
- data/lib/evil_events/core/events/manager_registry.rb +16 -0
- data/lib/evil_events/core/events/manager_registry/scoped_event_type_matcher.rb +177 -0
- data/lib/evil_events/core/events/notifier/sequential.rb +2 -2
- data/lib/evil_events/core/events/serializers.rb +13 -2
- data/lib/evil_events/core/events/serializers/base.rb +56 -13
- data/lib/evil_events/core/events/serializers/base/abstract_engine.rb +47 -0
- data/lib/evil_events/core/events/serializers/base/abstract_factory.rb +60 -0
- data/lib/evil_events/core/events/serializers/base/data_transformer.rb +57 -0
- data/lib/evil_events/core/events/serializers/base/event_serialization_state.rb +80 -0
- data/lib/evil_events/core/events/serializers/base/generic_config.rb +7 -0
- data/lib/evil_events/core/events/serializers/hash.rb +3 -73
- data/lib/evil_events/core/events/serializers/hash/config.rb +11 -0
- data/lib/evil_events/core/events/serializers/hash/engines.rb +10 -0
- data/lib/evil_events/core/events/serializers/hash/engines/native.rb +60 -0
- data/lib/evil_events/core/events/serializers/hash/factory.rb +65 -0
- data/lib/evil_events/core/events/serializers/hash/packer.rb +26 -0
- data/lib/evil_events/core/events/serializers/hash/unpacker.rb +24 -0
- data/lib/evil_events/core/events/serializers/json.rb +3 -59
- data/lib/evil_events/core/events/serializers/json/config.rb +11 -0
- data/lib/evil_events/core/events/serializers/json/engines.rb +10 -0
- data/lib/evil_events/core/events/serializers/json/engines/native.rb +43 -0
- data/lib/evil_events/core/events/serializers/json/factory.rb +65 -0
- data/lib/evil_events/core/events/serializers/json/packer.rb +26 -0
- data/lib/evil_events/core/events/serializers/json/unpacker.rb +31 -0
- data/lib/evil_events/core/events/serializers/message_pack.rb +7 -0
- data/lib/evil_events/core/events/serializers/message_pack/config.rb +17 -0
- data/lib/evil_events/core/events/serializers/message_pack/engines.rb +10 -0
- data/lib/evil_events/core/events/serializers/message_pack/engines/mpacker.rb +81 -0
- data/lib/evil_events/core/events/serializers/message_pack/factory.rb +65 -0
- data/lib/evil_events/core/events/serializers/message_pack/packer.rb +26 -0
- data/lib/evil_events/core/events/serializers/message_pack/unpacker.rb +24 -0
- data/lib/evil_events/core/events/serializers/xml.rb +7 -0
- data/lib/evil_events/core/events/serializers/xml/config.rb +11 -0
- data/lib/evil_events/core/events/serializers/xml/engines.rb +10 -0
- data/lib/evil_events/core/events/serializers/xml/engines/ox.rb +31 -0
- data/lib/evil_events/core/events/serializers/xml/factory.rb +65 -0
- data/lib/evil_events/core/events/serializers/xml/packer.rb +26 -0
- data/lib/evil_events/core/events/serializers/xml/unpacker.rb +24 -0
- data/lib/evil_events/core/events/subscriber/mixin.rb +26 -3
- data/lib/evil_events/core/system.rb +28 -2
- data/lib/evil_events/core/system/broadcaster.rb +11 -5
- data/lib/evil_events/core/system/event_builder.rb +98 -34
- data/lib/evil_events/core/system/event_manager.rb +12 -0
- data/lib/evil_events/core/system/mock.rb +30 -2
- data/lib/evil_events/emitter.rb +4 -2
- data/lib/evil_events/error.rb +21 -1
- data/lib/evil_events/serializer.rb +14 -0
- data/lib/evil_events/shared.rb +1 -3
- data/lib/evil_events/shared/any_config.rb +60 -0
- data/lib/evil_events/version.rb +2 -2
- metadata +85 -14
- data/.jrubyrc +0 -1
- data/lib/evil_events/core/events/event_extensions/adapter_customizable.rb +0 -49
- data/lib/evil_events/core/events/event_extensions/emittable.rb +0 -41
- data/lib/evil_events/shared/combined_context.rb +0 -124
- data/lib/evil_events/shared/combined_context/mixin.rb +0 -43
- data/lib/evil_events/shared/configurable.rb +0 -7
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module EvilEvents::Core::Events::EventExtensions
|
4
|
-
# @api private
|
5
|
-
# @since 0.1.0
|
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
|
20
|
-
# @since 0.1.0
|
21
|
-
def emit!
|
22
|
-
EvilEvents::Core::Bootstrap[:event_system].emit(self)
|
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
|
40
|
-
end
|
41
|
-
end
|
@@ -1,124 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module EvilEvents
|
4
|
-
module Shared
|
5
|
-
# @example
|
6
|
-
# class EventStorage
|
7
|
-
# attr_reader :events
|
8
|
-
#
|
9
|
-
# def initialize
|
10
|
-
# @events = []
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# def store_event(event)
|
14
|
-
# @events << event
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# storage = EventStorage.new
|
19
|
-
# event = 'test_event'
|
20
|
-
# clojure = proc { store_event(event) }
|
21
|
-
# context = EvilEvents::Shared::CombinedContext.new(storage, clojure)
|
22
|
-
#
|
23
|
-
# storage.events # => []
|
24
|
-
#
|
25
|
-
# context.evaluate
|
26
|
-
# storage.events # => ['test_event']
|
27
|
-
#
|
28
|
-
# context.evaluate
|
29
|
-
# storage.events # => ['test_event', 'test_event']
|
30
|
-
#
|
31
|
-
# @since 0.1.0
|
32
|
-
# @api public
|
33
|
-
class CombinedContext < BasicObject
|
34
|
-
# @since 0.1.0
|
35
|
-
CombinedContextError = ::Class.new(::StandardError)
|
36
|
-
# @since 0.1.0
|
37
|
-
NonProcClojureObjectError = ::Class.new(CombinedContextError)
|
38
|
-
|
39
|
-
# @return [Object]
|
40
|
-
#
|
41
|
-
# @since 0.1.0
|
42
|
-
attr_reader :__required_context__
|
43
|
-
|
44
|
-
# @return [Object]
|
45
|
-
#
|
46
|
-
# @since 0.1.0
|
47
|
-
attr_reader :__outer_context__
|
48
|
-
|
49
|
-
# @return [::Kernel]
|
50
|
-
#
|
51
|
-
# @since 0.1.0
|
52
|
-
attr_reader :__kernel_context__
|
53
|
-
|
54
|
-
# @return [Proc]
|
55
|
-
#
|
56
|
-
# @since 0.1.0
|
57
|
-
attr_reader :__clojure__
|
58
|
-
|
59
|
-
# @param required_context [Object]
|
60
|
-
# @param clojure [Proc]
|
61
|
-
#
|
62
|
-
# @since 0.1.0
|
63
|
-
def initialize(required_context, clojure)
|
64
|
-
::Kernel.raise NonProcClojureObjectError unless clojure.is_a?(::Proc)
|
65
|
-
|
66
|
-
@__required_context__ = required_context
|
67
|
-
@__outer_context__ = ::Kernel.eval('self', clojure.binding)
|
68
|
-
@__kernel_context__ = ::Kernel
|
69
|
-
@__clojure__ = clojure
|
70
|
-
end
|
71
|
-
|
72
|
-
# @return [Object]
|
73
|
-
#
|
74
|
-
# @see #method_missing
|
75
|
-
#
|
76
|
-
# @since 0.1.0
|
77
|
-
def evaluate
|
78
|
-
instance_eval(&__clojure__)
|
79
|
-
end
|
80
|
-
|
81
|
-
# @see #evaluate
|
82
|
-
#
|
83
|
-
# @since 0.1.0
|
84
|
-
def method_missing(method_name, *arguments, &block)
|
85
|
-
case
|
86
|
-
when __outer_context__.respond_to?(method_name)
|
87
|
-
__outer_context__.public_send(method_name, *arguments, &block)
|
88
|
-
when __required_context__.respond_to?(method_name)
|
89
|
-
__required_context__.public_send(method_name, *arguments, &block)
|
90
|
-
when __kernel_context__.respond_to?(method_name)
|
91
|
-
__kernel_context__.public_send(method_name, *arguments, &block)
|
92
|
-
else
|
93
|
-
super
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
# @see #method_missing
|
98
|
-
#
|
99
|
-
# @since 0.1.0
|
100
|
-
def respond_to_missing?(method_name, include_private = false)
|
101
|
-
__outer_context__.respond_to?(method_name) ||
|
102
|
-
__required_context__.respond_to?(method_name) ||
|
103
|
-
__kernel_context__.respond_to?(method_name) || super
|
104
|
-
end
|
105
|
-
|
106
|
-
# @see #method_missing
|
107
|
-
# @see #respond_to_missing?
|
108
|
-
#
|
109
|
-
# @since 0.1.0
|
110
|
-
def method(method_name)
|
111
|
-
case
|
112
|
-
when __outer_context__.respond_to?(method_name)
|
113
|
-
__outer_context__.method(method_name)
|
114
|
-
when __required_context__.respond_to?(method_name)
|
115
|
-
__required_context__.method(method_name)
|
116
|
-
when __kernel_context__.respond_to?(method_name)
|
117
|
-
__kernel_context__.method(method_name)
|
118
|
-
else
|
119
|
-
super
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module EvilEvents::Shared
|
4
|
-
class CombinedContext
|
5
|
-
# @example
|
6
|
-
# require 'securerandom'
|
7
|
-
#
|
8
|
-
# class Event
|
9
|
-
# extend EvilEvents::Shared::CombinedContext::Mixin
|
10
|
-
#
|
11
|
-
# class << self
|
12
|
-
# def type(type = nil)
|
13
|
-
# @type = type if type
|
14
|
-
# @type
|
15
|
-
# end
|
16
|
-
# end
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# def get_uuid
|
20
|
-
# SecureRandom.uuid
|
21
|
-
# end
|
22
|
-
#
|
23
|
-
# MyEvent = Event.evaluate do
|
24
|
-
# type get_uuid # Event.type + binding#get_uuid => works good :)
|
25
|
-
# end
|
26
|
-
#
|
27
|
-
# @see EvilEvents::Shared::CombinedContext
|
28
|
-
#
|
29
|
-
# @api public
|
30
|
-
# @since 0.1.0
|
31
|
-
module Mixin
|
32
|
-
# @param clojure [Proc]
|
33
|
-
# @return [Object] Clojure evaluation result
|
34
|
-
#
|
35
|
-
# @see EvilEvents::Shared::CombinedContext#evaluate
|
36
|
-
#
|
37
|
-
# @since 0.1.0
|
38
|
-
def evaluate(&clojure)
|
39
|
-
CombinedContext.new(self, clojure).evaluate
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|