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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 433dcd60c4b1a754d00e5a40051f8fce7f2b12c2
4
- data.tar.gz: 01a0271699af053fdb782fc7cf45fa888ecb64bd
3
+ metadata.gz: b17a12dbdfb330cac2d2475383de67bebdd1498c
4
+ data.tar.gz: 31d26f7afa8379bcf29a4324327b9ecf9aaa43dd
5
5
  SHA512:
6
- metadata.gz: e1f5c5576c528da60b273de597037843801ba553e645895518595e8eeeb2b58b6c9136c392bdb12f657b813b755a4fc61d7f47fa9008a8b038d27b4f8b37f443
7
- data.tar.gz: 1cb7b235ac6cbb07760cf6459f2e5848aabf35e9dcaf290b7c52d8d25c1a43ae313fe4706859c587f17745c66ea4792ac6b0c8fbebd781001aa4a8b4058d59f2
6
+ metadata.gz: 8e85ac645e23dfae0e21b8809b2eaeb642a836fd04128e0ce1c65be0c829b9dc4c171cc8cb5ffd33daa9e6c94b642214b2198495ad30264b4eab81d3ceb11433
7
+ data.tar.gz: 32a1931f5822e360902e59167319e75e16e1edd403e93b87e8b68ee9bfabe79ef37a1f05a54db1afb12518945e5adc2243ff41d895bb9a20b5645b0a221e794d
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ require: rubocop-rspec
3
3
  AllCops:
4
4
  DisplayCopNames: true
5
5
  DisplayStyleGuide: true
6
- TargetRubyVersion: 2.3
6
+ TargetRubyVersion: 2.4.2
7
7
  Include:
8
8
  - lib/**/*
9
9
  - spec/**/*
@@ -8,6 +8,6 @@ module EvilEvents
8
8
  extend Shared::DependencyContainer::Mixin
9
9
 
10
10
  register(:event_system, memoize: true) { EvilEvents::System.new }
11
- register(:config) { EvilEvents::Config }
11
+ register(:config, memoize: true) { EvilEvents::Config.new }
12
12
  end
13
13
  end
@@ -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
@@ -1,38 +1,55 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EvilEvents
4
- # @api public
4
+ # @api private
5
5
  # @since 0.1.0
6
- Config = EvilEvents::Shared::MockableClassBuilder.new_class do
7
- extend EvilEvents::Shared::Configurable
8
-
6
+ class Config
9
7
  class << self
10
- # @return [Class{EvilEvents::Shared::Configurable}]
11
- #
8
+ # @api private
12
9
  # @since 0.1.0
13
10
  def build_stub
14
- build_mock
11
+ new
15
12
  end
13
+ end
16
14
 
17
- # @return void
18
- #
19
- # @since 0.1.0
20
- def reset!
21
- config.adapter.default = :memory_sync
22
- config.subscriber.default_delegator = :call
23
- config.logger = EvilEvents::Shared::Logger.new(STDOUT)
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
- setting :adapter, reader: true do
28
- setting :default, :memory_sync
29
- end
33
+ private
30
34
 
31
- setting :subscriber, reader: true do
32
- setting :default_delegator, :call
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
- setting :logger, EvilEvents::Shared::Logger.new(STDOUT), reader: true
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
- extend EvilEvents::Shared::DependencyContainer::Mixin
7
+ include EvilEvents::Shared::DependencyContainer::Mixin
8
8
 
9
- register(:memory_sync) { Adapters::MemorySync }
10
- register(:memory_async) { Adapters::MemoryAsync }
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 # TODO: think about Dry::Types checker
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'] # TODO: || {} here
29
- event_metadata = hash[:metadata] || hash['metadata'] # TODO: || {} here
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] # TODO: || {} here
32
- event_metadata = json_hash[:metadata] # TODO: || {} here
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
- module Mixin
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 IncompatibleEventAttrTypeError
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 :module do
18
- Module.new { class_eval(&module_definitions) if block_given? }
17
+ define_method :module_clone do
18
+ ClonableModuleBuilder.build(&module_definitions)
19
19
  end
20
20
  end
21
21
  end
@@ -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 = EvilEvents::Core::Broadcasting::Emitter.new
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
- EvilEvents::Core::Broadcasting::Adapters.resolve(adapter_name)
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
- EvilEvents::Core::Broadcasting::Adapters.register(adapter_name, adapter_object)
56
+ adapters_container.register(adapter_name, adapter_object)
49
57
  end
50
58
  end
51
59
  end
@@ -3,5 +3,5 @@
3
3
  module EvilEvents
4
4
  # @api public
5
5
  # @since 0.1.0
6
- VERSION = '0.1.0rc5'
6
+ VERSION = '0.1.0rc6'
7
7
  end
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.module
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.0rc5
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-18 00:00:00.000000000 Z
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