evil_events 0.1.0rc5 → 0.1.0rc6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/lib/evil_events/boot_point.rb +1 -1
- data/lib/evil_events/config/adapters.rb +16 -0
- data/lib/evil_events/config.rb +37 -20
- data/lib/evil_events/core/broadcasting/adapters.rb +8 -3
- data/lib/evil_events/core/events/manager.rb +1 -1
- data/lib/evil_events/core/events/serializers/hash.rb +3 -3
- data/lib/evil_events/core/events/serializers/json.rb +2 -2
- data/lib/evil_events/core/events/subscriber/mixin.rb +2 -7
- data/lib/evil_events/shared/clonable_module_builder.rb +2 -2
- data/lib/evil_events/shared.rb +0 -1
- data/lib/evil_events/system/broadcaster.rb +11 -3
- data/lib/evil_events/version.rb +1 -1
- data/lib/evil_events.rb +23 -1
- metadata +2 -3
- data/lib/evil_events/shared/mockable_class_builder.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b17a12dbdfb330cac2d2475383de67bebdd1498c
|
4
|
+
data.tar.gz: 31d26f7afa8379bcf29a4324327b9ecf9aaa43dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e85ac645e23dfae0e21b8809b2eaeb642a836fd04128e0ce1c65be0c829b9dc4c171cc8cb5ffd33daa9e6c94b642214b2198495ad30264b4eab81d3ceb11433
|
7
|
+
data.tar.gz: 32a1931f5822e360902e59167319e75e16e1edd403e93b87e8b68ee9bfabe79ef37a1f05a54db1afb12518945e5adc2243ff41d895bb9a20b5645b0a221e794d
|
data/.rubocop.yml
CHANGED
@@ -4,10 +4,26 @@
|
|
4
4
|
# @since 0.1.0
|
5
5
|
module EvilEvents::Config::Adapters
|
6
6
|
class << self
|
7
|
+
# @params adapter_name [String, Symbol]
|
8
|
+
# @params adapter_object [Class{EvilEvents::DispatcherMixin}]
|
9
|
+
# @raise Dry::Container::Error
|
10
|
+
# @return void
|
11
|
+
#
|
7
12
|
# @api public
|
8
13
|
# @since 0.1.0
|
9
14
|
def register(adapter_name, adapter_object)
|
10
15
|
EvilEvents::BootPoint[:event_system].register_adapter(adapter_name, adapter_object)
|
11
16
|
end
|
17
|
+
|
18
|
+
# @param adapter_name [String, Symbol]
|
19
|
+
# @return [Class{EvilEvents::DispatcherMixin}]
|
20
|
+
# @raise Dry::Container::Error
|
21
|
+
#
|
22
|
+
# @api public
|
23
|
+
# @since 0.1.0
|
24
|
+
def resolve(adapter_name)
|
25
|
+
EvilEvents::BootPoint[:event_system].resolve_adapter(adapter_name)
|
26
|
+
end
|
27
|
+
alias_method :[], :resolve
|
12
28
|
end
|
13
29
|
end
|
data/lib/evil_events/config.rb
CHANGED
@@ -1,38 +1,55 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module EvilEvents
|
4
|
-
# @api
|
4
|
+
# @api private
|
5
5
|
# @since 0.1.0
|
6
|
-
Config
|
7
|
-
extend EvilEvents::Shared::Configurable
|
8
|
-
|
6
|
+
class Config
|
9
7
|
class << self
|
10
|
-
# @
|
11
|
-
#
|
8
|
+
# @api private
|
12
9
|
# @since 0.1.0
|
13
10
|
def build_stub
|
14
|
-
|
11
|
+
new
|
15
12
|
end
|
13
|
+
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
# @api private
|
16
|
+
# @since 0.1.0
|
17
|
+
def initialize
|
18
|
+
@config = Module.new do
|
19
|
+
extend EvilEvents::Shared::Configurable
|
20
|
+
|
21
|
+
setting :adapter, reader: true do
|
22
|
+
setting :default, :memory_sync
|
23
|
+
end
|
24
|
+
|
25
|
+
setting :subscriber, reader: true do
|
26
|
+
setting :default_delegator, :call
|
27
|
+
end
|
28
|
+
|
29
|
+
setting :logger, EvilEvents::Shared::Logger.new(STDOUT), reader: true
|
24
30
|
end
|
25
31
|
end
|
26
32
|
|
27
|
-
|
28
|
-
setting :default, :memory_sync
|
29
|
-
end
|
33
|
+
private
|
30
34
|
|
31
|
-
|
32
|
-
|
35
|
+
# @return [Module{EvilEvents::Shared::Configurable}]
|
36
|
+
#
|
37
|
+
# @api private
|
38
|
+
# @since 0.1.0
|
39
|
+
attr_reader :config
|
40
|
+
|
41
|
+
# @api private
|
42
|
+
# @since 0.1.0
|
43
|
+
def method_missing(method_name, *attributes, &block)
|
44
|
+
return super unless config.respond_to?(method_name)
|
45
|
+
config.public_send(method_name, *attributes, &block)
|
33
46
|
end
|
34
47
|
|
35
|
-
|
48
|
+
# @api private
|
49
|
+
# @since 0.1.0
|
50
|
+
def respond_to_missing?(method_name, include_private = false)
|
51
|
+
config.respond_to_missing?(method_name, include_private) || super
|
52
|
+
end
|
36
53
|
end
|
37
54
|
|
38
55
|
require_relative 'config/adapters'
|
@@ -4,9 +4,14 @@ module EvilEvents::Core::Broadcasting
|
|
4
4
|
# @api private
|
5
5
|
# @since 0.1.0
|
6
6
|
class Adapters
|
7
|
-
|
7
|
+
include EvilEvents::Shared::DependencyContainer::Mixin
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
# @return void
|
10
|
+
#
|
11
|
+
# @since 0.1.0
|
12
|
+
def register_core_adapters!
|
13
|
+
register(:memory_sync) { MemorySync }
|
14
|
+
register(:memory_async) { MemoryAsync }
|
15
|
+
end
|
11
16
|
end
|
12
17
|
end
|
@@ -37,7 +37,7 @@ module EvilEvents::Core::Events
|
|
37
37
|
# @since 0.1.0
|
38
38
|
def observe(raw_subscriber, delegator = nil)
|
39
39
|
case delegator
|
40
|
-
when NilClass, Symbol, String
|
40
|
+
when NilClass, Symbol, String
|
41
41
|
subscribers.push(create_event_subscriber(raw_subscriber, delegator))
|
42
42
|
else
|
43
43
|
raise InvalidDelegatorTypeError
|
@@ -22,11 +22,11 @@ class EvilEvents::Core::Events::Serializers
|
|
22
22
|
# @return [EvilEvents::Core::Events::AbstractEvent]
|
23
23
|
#
|
24
24
|
# @since 0.1.0
|
25
|
-
def deserialize(hash)
|
25
|
+
def deserialize(hash) # rubocop:disable Metrics/AbcSize
|
26
26
|
raise DeserializationError unless hash.is_a?(::Hash)
|
27
27
|
event_type = hash[:type] || hash['type']
|
28
|
-
event_payload = hash[:payload] || hash['payload']
|
29
|
-
event_metadata = hash[:metadata] || hash['metadata']
|
28
|
+
event_payload = hash[:payload] || hash['payload']
|
29
|
+
event_metadata = hash[:metadata] || hash['metadata']
|
30
30
|
raise DeserializationError unless event_type && event_payload && event_metadata
|
31
31
|
raise DeserializationError unless event_payload.is_a?(::Hash) && event_metadata.is_a?(::Hash)
|
32
32
|
|
@@ -28,8 +28,8 @@ class EvilEvents::Core::Events::Serializers
|
|
28
28
|
begin
|
29
29
|
json_hash = ::JSON.parse(json, symbolize_names: true)
|
30
30
|
event_type = json_hash[:type]
|
31
|
-
event_payload = json_hash[:payload]
|
32
|
-
event_metadata = json_hash[:metadata]
|
31
|
+
event_payload = json_hash[:payload]
|
32
|
+
event_metadata = json_hash[:metadata]
|
33
33
|
raise DeserializationError unless event_type && event_payload && event_metadata
|
34
34
|
rescue ::JSON::ParserError
|
35
35
|
raise DeserializationError
|
@@ -3,12 +3,7 @@
|
|
3
3
|
class EvilEvents::Core::Events::Subscriber
|
4
4
|
# @api public
|
5
5
|
# @since 0.1.0
|
6
|
-
|
7
|
-
# @since 0.1.0
|
8
|
-
SubscriberMixinError = Class.new(StandardError)
|
9
|
-
# @since 0.1.0
|
10
|
-
IncompatibleEventAttrTypeError = Class.new(SubscriberMixinError)
|
11
|
-
|
6
|
+
Mixin = EvilEvents::Shared::ClonableModuleBuilder.build do
|
12
7
|
# @param event_type [String, Class{EvilEvents::Core::Events::AbstractEvent}]
|
13
8
|
# @param delegator [String, Symbol, NilClass]
|
14
9
|
# @raise [IncompatibleEventAttrTypeError]
|
@@ -21,7 +16,7 @@ class EvilEvents::Core::Events::Subscriber
|
|
21
16
|
when String
|
22
17
|
EvilEvents::BootPoint[:event_system].raw_observe(event_type, self, delegator)
|
23
18
|
else
|
24
|
-
raise
|
19
|
+
raise ArgumentError
|
25
20
|
end
|
26
21
|
end
|
27
22
|
end
|
@@ -14,8 +14,8 @@ module EvilEvents::Shared
|
|
14
14
|
class_eval(&module_definitions) if block_given?
|
15
15
|
|
16
16
|
singleton_class.instance_eval do
|
17
|
-
define_method :
|
18
|
-
|
17
|
+
define_method :module_clone do
|
18
|
+
ClonableModuleBuilder.build(&module_definitions)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/lib/evil_events/shared.rb
CHANGED
@@ -11,7 +11,6 @@ module EvilEvents
|
|
11
11
|
require_relative 'shared/combined_context'
|
12
12
|
require_relative 'shared/delegator_resolver'
|
13
13
|
require_relative 'shared/dependency_container'
|
14
|
-
require_relative 'shared/mockable_class_builder'
|
15
14
|
require_relative 'shared/combined_context_mixin'
|
16
15
|
require_relative 'shared/clonable_module_builder'
|
17
16
|
end
|
@@ -9,9 +9,17 @@ class EvilEvents::System
|
|
9
9
|
# @since 0.1.0
|
10
10
|
attr_reader :event_emitter
|
11
11
|
|
12
|
+
# @return [EvilEvents::Core::Broadcasting::Adapters]
|
13
|
+
#
|
14
|
+
# @since 0.1.0
|
15
|
+
attr_reader :adapters_container
|
16
|
+
|
12
17
|
# @since 0.1.0
|
13
18
|
def initialize
|
14
|
-
@event_emitter
|
19
|
+
@event_emitter = EvilEvents::Core::Broadcasting::Emitter.new
|
20
|
+
@adapters_container = EvilEvents::Core::Broadcasting::Adapters.new
|
21
|
+
|
22
|
+
@adapters_container.register_core_adapters!
|
15
23
|
end
|
16
24
|
|
17
25
|
# @param event [EvilEvents::Core::Events::AbstractEvent]
|
@@ -36,7 +44,7 @@ class EvilEvents::System
|
|
36
44
|
#
|
37
45
|
# @since 0.1.0
|
38
46
|
def resolve_adapter(adapter_name)
|
39
|
-
|
47
|
+
adapters_container.resolve(adapter_name)
|
40
48
|
end
|
41
49
|
|
42
50
|
# @param adapter_name [Symbol, String]
|
@@ -45,7 +53,7 @@ class EvilEvents::System
|
|
45
53
|
#
|
46
54
|
# @since 0.1.0
|
47
55
|
def register_adapter(adapter_name, adapter_object)
|
48
|
-
|
56
|
+
adapters_container.register(adapter_name, adapter_object)
|
49
57
|
end
|
50
58
|
end
|
51
59
|
end
|
data/lib/evil_events/version.rb
CHANGED
data/lib/evil_events.rb
CHANGED
@@ -25,7 +25,29 @@ module EvilEvents
|
|
25
25
|
|
26
26
|
# @api public
|
27
27
|
# @since 0.1.0
|
28
|
-
DispatcherMixin = EvilEvents::Core::Broadcasting::Dispatcher::Mixin.
|
28
|
+
DispatcherMixin = EvilEvents::Core::Broadcasting::Dispatcher::Mixin.module_clone
|
29
|
+
|
30
|
+
# @api piblic
|
31
|
+
# @since 0.1.0
|
32
|
+
SubscriberMixin = EvilEvents::Core::Events::Subscriber::Mixin.module_clone
|
33
|
+
|
34
|
+
class << self
|
35
|
+
# @see EvilEvents::Config
|
36
|
+
# @api public
|
37
|
+
# @since 0.1.0
|
38
|
+
def configure
|
39
|
+
EvilEvents::BootPoint[:config].configure do |config|
|
40
|
+
yield(config) if block_given?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# @see EvilEvents::Config
|
45
|
+
# @api public
|
46
|
+
# @since 0.1.0
|
47
|
+
def config
|
48
|
+
EvilEvents::BootPoint[:config]
|
49
|
+
end
|
50
|
+
end
|
29
51
|
|
30
52
|
# @api public
|
31
53
|
# @since 0.1.0
|
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.
|
4
|
+
version: 0.1.0rc6
|
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-
|
11
|
+
date: 2017-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-monads
|
@@ -285,7 +285,6 @@ files:
|
|
285
285
|
- lib/evil_events/shared/delegator_resolver.rb
|
286
286
|
- lib/evil_events/shared/dependency_container.rb
|
287
287
|
- lib/evil_events/shared/logger.rb
|
288
|
-
- lib/evil_events/shared/mockable_class_builder.rb
|
289
288
|
- lib/evil_events/shared/structure.rb
|
290
289
|
- lib/evil_events/shared/types.rb
|
291
290
|
- lib/evil_events/system.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module EvilEvents::Shared
|
4
|
-
# @api public
|
5
|
-
# @since 0.1.0
|
6
|
-
module MockableClassBuilder
|
7
|
-
class << self
|
8
|
-
# @param class_definitions [Proc]
|
9
|
-
# @return [Class]
|
10
|
-
#
|
11
|
-
# @since 0.1.0
|
12
|
-
def new_class(&class_definitions)
|
13
|
-
Class.new.tap do |klass|
|
14
|
-
klass.class_eval(&class_definitions) if block_given?
|
15
|
-
|
16
|
-
klass.singleton_class.class_eval do
|
17
|
-
define_method :build_mock do
|
18
|
-
::Class.new.tap do |mocking_class|
|
19
|
-
mocking_class.class_eval(&class_definitions)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|