evil_events 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +3 -0
  4. data/.travis.yml +30 -7
  5. data/CHANGELOG.md +24 -0
  6. data/Gemfile +0 -3
  7. data/bin/rspec +62 -0
  8. data/evil_events.gemspec +3 -5
  9. data/gemfiles/with_native_extensions.gemfile +9 -0
  10. data/gemfiles/without_native_extensions.gemfile +5 -0
  11. data/lib/evil_events.rb +1 -3
  12. data/lib/evil_events/config.rb +2 -2
  13. data/lib/evil_events/core/activity_logger.rb +1 -1
  14. data/lib/evil_events/core/config.rb +31 -39
  15. data/lib/evil_events/core/events.rb +0 -2
  16. data/lib/evil_events/core/events/event_extensions/dispatchable.rb +1 -1
  17. data/lib/evil_events/core/events/event_extensions/observable.rb +3 -1
  18. data/lib/evil_events/core/events/notifier/builder.rb +3 -3
  19. data/lib/evil_events/core/events/notifier/sequential.rb +2 -2
  20. data/lib/evil_events/core/events/notifier/worker/executor.rb +1 -1
  21. data/lib/evil_events/core/events/serializers/base/generic_config.rb +3 -1
  22. data/lib/evil_events/core/events/serializers/hash/config.rb +1 -3
  23. data/lib/evil_events/core/events/serializers/hash/factory.rb +3 -6
  24. data/lib/evil_events/core/events/serializers/json/config.rb +1 -3
  25. data/lib/evil_events/core/events/serializers/json/factory.rb +3 -6
  26. data/lib/evil_events/core/events/serializers/message_pack/config.rb +1 -9
  27. data/lib/evil_events/core/events/serializers/message_pack/engines/.keep +0 -0
  28. data/lib/evil_events/core/events/serializers/message_pack/factory.rb +3 -7
  29. data/lib/evil_events/core/events/serializers/xml/config.rb +1 -3
  30. data/lib/evil_events/core/events/serializers/xml/engines/.keep +0 -0
  31. data/lib/evil_events/core/events/serializers/xml/factory.rb +3 -6
  32. data/lib/evil_events/core/events/subscriber.rb +1 -1
  33. data/lib/evil_events/plugins.rb +10 -4
  34. data/lib/evil_events/plugins/mpacker_engine.rb +37 -0
  35. data/lib/evil_events/plugins/mpacker_engine/config.rb +13 -0
  36. data/lib/evil_events/{core/events/serializers/message_pack/engines → plugins/mpacker_engine}/mpacker.rb +9 -9
  37. data/lib/evil_events/plugins/oj_engine.rb +36 -0
  38. data/lib/evil_events/plugins/oj_engine/oj.rb +43 -0
  39. data/lib/evil_events/plugins/ox_engine.rb +36 -0
  40. data/lib/evil_events/{core/events/serializers/xml/engines → plugins/ox_engine}/ox.rb +4 -4
  41. data/lib/evil_events/shared/structure.rb +3 -3
  42. data/lib/evil_events/version.rb +2 -2
  43. metadata +21 -41
  44. data/lib/evil_events/plugins/redis_adapter.rb +0 -6
  45. data/lib/evil_events/plugins/sidekiq_adapter.rb +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebb72755c7492ae455bb03f369b5751a39afdcccda53ad047b820233a82e511c
4
- data.tar.gz: 8c603db8c385f308b674a8f34bf2b18c9ac14973c2cbab875b7c017500ec7384
3
+ metadata.gz: f55a8e9f05384af9d9f133b3672c10d646468aa4fb6c0bbd2f0e1cc0f511933e
4
+ data.tar.gz: b3cc8858a7b2d8840033da96e58e63cdeb50a52a9b413e473c381cee9e4d5283
5
5
  SHA512:
6
- metadata.gz: 5c9a12d72f309306e5ebbd5284998715574196e57a643809cdb9f45daa4a9595c8b446d31460557c14ea72795aae42079fd0d86239ef0aba0eec5fb4645533b9
7
- data.tar.gz: 13d6e35c94e8700cb49779a593cd8825c1bd50713165fc1524b2a13135bb4ef4418ad185f0f5fe2b443c79502159bb23660f8a70ffc694f7536e2c187094cc34
6
+ metadata.gz: 16dee4d83a1a16336732aa196b2c3946c4762e722a2f5a8c28c61e90f35d5edcf649d9d674401bfb40a5eab2f1cdebc3ddb7979b00b4dabfd954e47396b093b8
7
+ data.tar.gz: f259fb9d9ef65be8f20b6becefe36b379c9e01e1d435d395541eee38ce67005d85df58e3c7a771a4f13caef59033b375b5c109202e31735cb490e1da395b1e62
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
  /tmp/
10
10
  .rspec_status
11
11
  .ruby-version
12
+ gemfiles/*.lock
13
+ *.gem
@@ -125,3 +125,6 @@ RSpec/AnyInstance:
125
125
 
126
126
  RSpec/ExpectChange:
127
127
  Enabled: false
128
+
129
+ Bundler/OrderedGems:
130
+ Enabled: false
@@ -1,12 +1,35 @@
1
1
  language: ruby
2
- rvm:
3
- - 2.2.10
4
- - 2.3.7
5
- - 2.4.4
6
- - 2.5.1
7
- - ruby-head
8
-
9
2
  sudo: false
10
3
  before_install: gem install bundler
11
4
  cache: bundler
12
5
  script: bundle exec rspec
6
+ matrix:
7
+ fast_finish: true
8
+ include:
9
+ - rvm: 2.2.10
10
+ gemfile: gemfiles/with_native_extensions.gemfile
11
+ env: TEST_NATIVE_EXTENSIONS=true
12
+ - rvm: 2.3.7
13
+ gemfile: gemfiles/with_native_extensions.gemfile
14
+ env: TEST_NATIVE_EXTENSIONS=true
15
+ - rvm: 2.4.4
16
+ gemfile: gemfiles/with_native_extensions.gemfile
17
+ env: TEST_NATIVE_EXTENSIONS=true
18
+ - rvm: 2.5.1
19
+ gemfile: gemfiles/with_native_extensions.gemfile
20
+ env: TEST_NATIVE_EXTENSIONS=true
21
+ - rvm: ruby-head
22
+ gemfile: gemfiles/with_native_extensions.gemfile
23
+ env: TEST_NATIVE_EXTENSIONS=true
24
+ - rvm: 2.2.10
25
+ gemfile: gemfiles/without_native_extensions.gemfile
26
+ - rvm: 2.3.7
27
+ gemfile: gemfiles/without_native_extensions.gemfile
28
+ - rvm: 2.4.4
29
+ gemfile: gemfiles/without_native_extensions.gemfile
30
+ - rvm: 2.5.1
31
+ gemfile: gemfiles/without_native_extensions.gemfile
32
+ - rvm: ruby-head
33
+ gemfile: gemfiles/without_native_extensions.gemfile
34
+ - rvm: jruby-head
35
+ gemfile: gemfiles/without_native_extensions.gemfile
@@ -1,6 +1,30 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.5.0] - 2018-05-20
5
+ ### Added
6
+ - Added Oj serialization engine for JSON format;
7
+ - JRuby is BACK! 💣
8
+
9
+ ### Changed
10
+ - No more `dry-configurable` dependency => gem `qonfig` is used instead;
11
+ - Moved to plugins:
12
+ - Ox serialization engine:
13
+ - requires `gem ox ~> 2.9.2`;
14
+ - configuration:
15
+ - `EvilEvents::Plugins.load! :ox_engine`
16
+ - `EvilEvents::Config.configure { |c| c.serializers.xml.engine = :ox }`
17
+ - Oj serialization engine:
18
+ - requires `gem oj ~> 3.6.0`
19
+ - configuration:
20
+ - `EvilEvents::Plugins.load! :oj_engine`
21
+ - `EvilEvents::Config.configure { |c| c.serializers.json.engine = :oj }`
22
+ - Mpacker serialization engine (uses gem `msgpack` with native dependencies)
23
+ - requires `gem msgpack ~> 1.2.4`
24
+ - configuration:
25
+ - `EvilEvents::Plugins.load! :mpacker_engine`
26
+ - `EvilEvents::Config.configure { |c| c.serializers.msgpack.engine = :mpacker }`
27
+
4
28
  ## [0.4.0] - 2018-05-02
5
29
  ### Added
6
30
  - **Routing Key Based Event Types**. A new way of subscribing to events and approach to event naming: routing-key-based event naming;
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in evil_events.gemspec
6
3
  gemspec
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'pathname'
5
+ require 'optparse'
6
+
7
+ module EvilEventsSpecRunner
8
+ GEMFILES = {
9
+ with_native: File.expand_path(
10
+ File.join('..', '..', 'gemfiles', 'with_native_extensions.gemfile'),
11
+ Pathname.new(__FILE__).realpath
12
+ ),
13
+
14
+ without_naitve: File.expand_path(
15
+ File.join('..', '..', 'gemfiles', 'without_native_extensions.gemfile'),
16
+ Pathname.new(__FILE__).realpath
17
+ )
18
+ }.freeze
19
+
20
+ class << self
21
+ def run!
22
+ OptionParser.new do |opts|
23
+ opts.banner = 'Usage: bin/rspec [options]'
24
+
25
+ opts.on('-w', '--without-native-extensions', 'Test without native extensions') do
26
+ run_without_native_extensions!
27
+ end
28
+
29
+ opts.on('-n', '--with-native-extensions', 'Test with native extensions') do
30
+ run_with_native_extensions!
31
+ end
32
+
33
+ opts.on('-h', '--help', 'Show this message') do
34
+ puts opts
35
+ end
36
+ end.parse!
37
+ end
38
+
39
+ private
40
+
41
+ def run_with_native_extensions!
42
+ ENV['TEST_NATIVE_EXTENSIONS'] = 'true'
43
+ ENV['BUNDLE_GEMFILE'] = GEMFILES[:with_native]
44
+
45
+ run_tests!
46
+ end
47
+
48
+ def run_without_native_extensions!
49
+ ENV['BUNDLE_GEMFILE'] = GEMFILES[:without_native]
50
+
51
+ run_tests!
52
+ end
53
+
54
+ def run_tests!
55
+ require 'rubygems'
56
+ require 'bundler/setup'
57
+ load Gem.bin_path('rspec-core', 'rspec')
58
+ end
59
+ end
60
+ end
61
+
62
+ EvilEventsSpecRunner.run!
@@ -27,14 +27,12 @@ Gem::Specification.new do |spec|
27
27
  end
28
28
 
29
29
  spec.add_dependency 'dry-monads', '~> 0.4.0'
30
- spec.add_dependency 'dry-types', '~> 0.12.2'
31
- spec.add_dependency 'dry-struct', '~> 0.3.1'
32
- spec.add_dependency 'dry-configurable', '~> 0.7.0'
30
+ spec.add_dependency 'dry-types', '~> 0.13.0'
31
+ spec.add_dependency 'dry-struct', '~> 0.5.0'
33
32
  spec.add_dependency 'dry-container', '~> 0.6.0'
34
33
  spec.add_dependency 'concurrent-ruby', '~> 1.0.5'
35
34
  spec.add_dependency 'symbiont-ruby', '~> 0.2.0'
36
- spec.add_dependency 'ox', '~> 2.9.2'
37
- spec.add_dependency 'msgpack', '~> 1.2.4'
35
+ spec.add_dependency 'qonfig', '~> 0.1.0'
38
36
 
39
37
  spec.add_development_dependency 'coveralls', '~> 0.8.21'
40
38
  spec.add_development_dependency 'simplecov', '~> 0.14.1'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'ox', '~> 2.9.2'
6
+ gem 'oj', '~> 3.6.0'
7
+ gem 'msgpack', '~> 1.2.4'
8
+
9
+ gemspec path: '..'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec path: '..'
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry-configurable'
4
3
  require 'dry-container'
5
4
  require 'dry-struct'
6
5
  require 'dry-types'
@@ -9,10 +8,9 @@ require 'concurrent/map'
9
8
  require 'symbiont'
10
9
  require 'securerandom'
11
10
  require 'forwardable'
12
- require 'msgpack'
11
+ require 'qonfig'
13
12
  require 'logger'
14
13
  require 'json'
15
- require 'ox'
16
14
 
17
15
  # @api public
18
16
  # @since 0.1.0
@@ -12,14 +12,14 @@ module EvilEvents
12
12
  # @api public
13
13
  # @since 0.1.0
14
14
  def options
15
- EvilEvents::Core::Bootstrap[:config]
15
+ EvilEvents::Core::Bootstrap[:config].settings
16
16
  end
17
17
 
18
18
  # @see EvilEvents::Core::Config
19
19
  # @api public
20
20
  # @since 0.1.0
21
21
  def configure
22
- options.configure { |conf| yield(conf) if block_given? }
22
+ EvilEvents::Core::Bootstrap[:config].configure { |conf| yield(conf) if block_given? }
23
23
  end
24
24
 
25
25
  # @see EvilEvents::Config::Types
@@ -21,7 +21,7 @@ module EvilEvents::Core
21
21
  #
22
22
  # @since 0.1.0
23
23
  def logger
24
- EvilEvents::Core::Bootstrap[:config].logger
24
+ EvilEvents::Core::Bootstrap[:config].settings.logger
25
25
  end
26
26
  end
27
27
  end
@@ -3,7 +3,7 @@
3
3
  module EvilEvents::Core
4
4
  # @api private
5
5
  # @since 0.1.0
6
- class Config < EvilEvents::Shared::AnyConfig
6
+ class Config < Qonfig::DataSet
7
7
  class << self
8
8
  # @api private
9
9
  # @since 0.1.0
@@ -12,55 +12,47 @@ module EvilEvents::Core
12
12
  end
13
13
  end
14
14
 
15
- # rubocop:disable Metrics/BlockLength
16
- configure do
17
- setting :serializers, reader: true do
18
- setting :json do
19
- setting :engine, :native
20
- end
21
-
22
- setting :hashing do
23
- setting :engine, :native
24
- end
25
-
26
- setting :xml do
27
- setting :engine, :ox
28
- end
29
-
30
- setting :msgpack do
31
- setting :engine, :mpacker
15
+ setting :serializers do
16
+ setting :json do
17
+ setting :engine, :native
18
+ end
32
19
 
33
- setting :mpacker do
34
- setting :configurator, ->(engine) {}
35
- end
36
- end
20
+ setting :hashing do
21
+ setting :engine, :native
37
22
  end
38
23
 
39
- setting :adapter, reader: true do
40
- setting :default, :memory_sync
24
+ setting :xml do
25
+ setting :engine, :ox
41
26
  end
42
27
 
43
- setting :subscriber, reader: true do
44
- setting :default_delegator, :call
28
+ setting :msgpack do
29
+ setting :engine
45
30
  end
31
+ end
46
32
 
47
- setting :logger, EvilEvents::Shared::Logger.new(STDOUT), reader: true
33
+ setting :adapter do
34
+ setting :default, :memory_sync
35
+ end
36
+
37
+ setting :subscriber do
38
+ setting :default_delegator, :call
39
+ end
48
40
 
49
- setting :notifier, reader: true do
50
- setting :type, :sequential
41
+ setting :logger, EvilEvents::Shared::Logger.new(STDOUT)
51
42
 
52
- setting :sequential, reader: true do
53
- # NOTE: place future settings here
54
- end
43
+ setting :notifier do
44
+ setting :type, :sequential
45
+
46
+ setting :sequential do
47
+ # NOTE: place future settings here
48
+ end
55
49
 
56
- setting :worker, reader: true do
57
- setting :min_threads, 0
58
- setting :max_threads, 5
59
- setting :max_queue, 1000
60
- setting :fallback_policy, :main_thread
61
- end
50
+ setting :worker do
51
+ setting :min_threads, 0
52
+ setting :max_threads, 5
53
+ setting :max_queue, 1000
54
+ setting :fallback_policy, :main_thread
62
55
  end
63
56
  end
64
- # rubocop:enable Metrics/BlockLength
65
57
  end
66
58
  end
@@ -27,14 +27,12 @@ module EvilEvents::Core
27
27
  require_relative 'events/serializers/hash/unpacker'
28
28
  require_relative 'events/serializers/xml'
29
29
  require_relative 'events/serializers/xml/engines'
30
- require_relative 'events/serializers/xml/engines/ox'
31
30
  require_relative 'events/serializers/xml/config'
32
31
  require_relative 'events/serializers/xml/factory'
33
32
  require_relative 'events/serializers/xml/packer'
34
33
  require_relative 'events/serializers/xml/unpacker'
35
34
  require_relative 'events/serializers/message_pack'
36
35
  require_relative 'events/serializers/message_pack/engines'
37
- require_relative 'events/serializers/message_pack/engines/mpacker'
38
36
  require_relative 'events/serializers/message_pack/config'
39
37
  require_relative 'events/serializers/message_pack/factory'
40
38
  require_relative 'events/serializers/message_pack/packer'
@@ -52,7 +52,7 @@ module EvilEvents::Core::Events::EventExtensions
52
52
  #
53
53
  # @since 0.4.0
54
54
  def adapter_name
55
- @adapter_identifier || EvilEvents::Core::Bootstrap[:config].adapter.default
55
+ @adapter_identifier || EvilEvents::Core::Bootstrap[:config].settings.adapter.default
56
56
  end
57
57
 
58
58
  # @option id [NilClass,Object]
@@ -36,7 +36,9 @@ module EvilEvents::Core::Events::EventExtensions
36
36
  # @since 0.1.0
37
37
  def default_delegator(delegator = nil)
38
38
  @default_delegator = delegator if delegator
39
- @default_delegator || EvilEvents::Core::Bootstrap[:config].subscriber.default_delegator
39
+ @default_delegator || begin
40
+ EvilEvents::Core::Bootstrap[:config].settings.subscriber.default_delegator
41
+ end
40
42
  end
41
43
 
42
44
  # @return [Array]
@@ -11,7 +11,7 @@ module EvilEvents::Core::Events::Notifier
11
11
  # @api private
12
12
  # @since 0.3.0
13
13
  def build_notifier!
14
- case EvilEvents::Core::Bootstrap[:config].notifier.type
14
+ case EvilEvents::Core::Bootstrap[:config].settings.notifier.type
15
15
  when :sequential then build_sequential_notifier!
16
16
  when :worker then build_worker_notifier!
17
17
  else
@@ -26,7 +26,7 @@ module EvilEvents::Core::Events::Notifier
26
26
  # @api private
27
27
  # @since 0.3.0
28
28
  def build_sequential_notifier!
29
- options = EvilEvents::Core::Bootstrap[:config].notifier.sequential.to_h
29
+ options = EvilEvents::Core::Bootstrap[:config].to_h[:notifier][:sequential]
30
30
  Sequential.new(**options)
31
31
  end
32
32
 
@@ -35,7 +35,7 @@ module EvilEvents::Core::Events::Notifier
35
35
  # @api private
36
36
  # @since 0.3.0
37
37
  def build_worker_notifier!
38
- options = EvilEvents::Core::Bootstrap[:config].notifier.worker.to_h
38
+ options = EvilEvents::Core::Bootstrap[:config].to_h[:notifier][:worker]
39
39
  Worker.new(**options)
40
40
  end
41
41
  end
@@ -25,11 +25,11 @@ module EvilEvents::Core::Events::Notifier
25
25
 
26
26
  log_success(event, subscriber)
27
27
  rescue StandardError => error
28
+ log_failure(event, subscriber)
29
+
28
30
  event.__call_on_error_hooks__(error)
29
31
 
30
32
  errors_stack << error
31
-
32
- log_failure(event, subscriber)
33
33
  end
34
34
  end
35
35
 
@@ -60,8 +60,8 @@ class EvilEvents::Core::Events::Notifier::Worker::Executor
60
60
  end.on_success do
61
61
  log_success(job.event, job.subscriber)
62
62
  end.on_error do |error|
63
- job.event.__call_on_error_hooks__(error)
64
63
  log_failure(job.event, job.subscriber)
64
+ job.event.__call_on_error_hooks__(error)
65
65
  end.execute
66
66
  rescue Concurrent::RejectedExecutionError
67
67
  raise EvilEvents::WorkerDisabledOrBusyError
@@ -3,5 +3,7 @@
3
3
  class EvilEvents::Core::Events::Serializers::Base
4
4
  # @api private
5
5
  # @since 0.4.0
6
- GenericConfig = Class.new(EvilEvents::Shared::AnyConfig)
6
+ class GenericConfig < Qonfig::DataSet
7
+ setting :options
8
+ end
7
9
  end
@@ -4,8 +4,6 @@ class EvilEvents::Core::Events::Serializers
4
4
  class Hash
5
5
  # @api private
6
6
  # @since 0.4.0
7
- class Config < Base::GenericConfig
8
- configure { setting :engine, reader: true }
9
- end
7
+ Config = Class.new(Base::GenericConfig)
10
8
  end
11
9
  end
@@ -10,11 +10,8 @@ class EvilEvents::Core::Events::Serializers
10
10
  # @api private
11
11
  # @since 0.4.0
12
12
  def build_config
13
- settings = EvilEvents::Core::Bootstrap[:config].serializers.hashing
14
-
15
- Config.new do |config|
16
- config.engine = settings.engine
17
- end
13
+ options = EvilEvents::Core::Bootstrap[:config].settings.serializers.hashing
14
+ Config.new.tap { |conf| conf.settings.options = options }
18
15
  end
19
16
 
20
17
  # @param config [Hash::Config]
@@ -24,7 +21,7 @@ class EvilEvents::Core::Events::Serializers
24
21
  # @api private
25
22
  # @since 0.4.0
26
23
  def build_engine(config)
27
- Engines.resolve(config.engine).new(config)
24
+ Engines.resolve(config.settings.options[:engine]).new(config)
28
25
  rescue Dry::Container::Error
29
26
  raise EvilEvents::UnrecognizedSerializationEngineError
30
27
  end
@@ -4,8 +4,6 @@ class EvilEvents::Core::Events::Serializers
4
4
  class JSON
5
5
  # @api private
6
6
  # @since 0.4.0
7
- class Config < Base::GenericConfig
8
- configure { setting :engine, reader: true }
9
- end
7
+ Config = Class.new(Base::GenericConfig)
10
8
  end
11
9
  end
@@ -10,11 +10,8 @@ class EvilEvents::Core::Events::Serializers
10
10
  # @api private
11
11
  # @since 0.4.0
12
12
  def build_config
13
- settings = EvilEvents::Core::Bootstrap[:config].serializers.json
14
-
15
- Config.new do |config|
16
- config.engine = settings.engine
17
- end
13
+ options = EvilEvents::Core::Bootstrap[:config].settings.serializers.json
14
+ Config.new.tap { |conf| conf.settings.options = options }
18
15
  end
19
16
 
20
17
  # @param config [JSON::Config]
@@ -24,7 +21,7 @@ class EvilEvents::Core::Events::Serializers
24
21
  # @api private
25
22
  # @since 0.4.0
26
23
  def build_engine(config)
27
- Engines.resolve(config.engine).new(config)
24
+ Engines.resolve(config.settings.options[:engine]).new(config)
28
25
  rescue Dry::Container::Error
29
26
  raise EvilEvents::UnrecognizedSerializationEngineError
30
27
  end
@@ -4,14 +4,6 @@ class EvilEvents::Core::Events::Serializers
4
4
  class MessagePack
5
5
  # @api private
6
6
  # @since 0.4.0
7
- class Config < Base::GenericConfig
8
- configure do
9
- setting :engine, reader: true
10
-
11
- setting :mpacker, reader: true do
12
- setting :configurator, ->(engine) {}
13
- end
14
- end
15
- end
7
+ Config = Class.new(Base::GenericConfig)
16
8
  end
17
9
  end
@@ -10,12 +10,8 @@ class EvilEvents::Core::Events::Serializers
10
10
  # @api private
11
11
  # @since 0.4.0
12
12
  def build_config
13
- settings = EvilEvents::Core::Bootstrap[:config].serializers.msgpack
14
-
15
- Config.new do |config|
16
- config.engine = settings.engine
17
- config.mpacker.configurator = settings.mpacker.configurator
18
- end
13
+ options = EvilEvents::Core::Bootstrap[:config].settings.serializers.msgpack
14
+ Config.new.tap { |conf| conf.settings.options = options }
19
15
  end
20
16
 
21
17
  # @param config [MessagePack::Config]
@@ -25,7 +21,7 @@ class EvilEvents::Core::Events::Serializers
25
21
  # @api private
26
22
  # @since 0.4.0
27
23
  def build_engine(config)
28
- Engines.resolve(config.engine).new(config)
24
+ Engines.resolve(config.settings.options[:engine]).new(config)
29
25
  rescue Dry::Container::Error
30
26
  raise EvilEvents::UnrecognizedSerializationEngineError
31
27
  end
@@ -4,8 +4,6 @@ class EvilEvents::Core::Events::Serializers
4
4
  class XML
5
5
  # @api private
6
6
  # @since 0.4.0
7
- class Config < Base::GenericConfig
8
- configure { setting :engine, reader: true }
9
- end
7
+ Config = Class.new(Base::GenericConfig)
10
8
  end
11
9
  end
@@ -10,11 +10,8 @@ class EvilEvents::Core::Events::Serializers
10
10
  # @api private
11
11
  # @since 0.4.0
12
12
  def build_config
13
- settings = EvilEvents::Core::Bootstrap[:config].serializers.xml
14
-
15
- Config.new do |config|
16
- config.engine = settings.engine
17
- end
13
+ options = EvilEvents::Core::Bootstrap[:config].settings.serializers.xml
14
+ Config.new.tap { |conf| conf.settings.options = options }
18
15
  end
19
16
 
20
17
  # @param config [XML::Config]
@@ -24,7 +21,7 @@ class EvilEvents::Core::Events::Serializers
24
21
  # @api private
25
22
  # @since 0.4.0
26
23
  def build_engine(config)
27
- Engines.resolve(config.engine).new(config)
24
+ Engines.resolve(config.settings.options[:engine]).new(config)
28
25
  rescue Dry::Container::Error
29
26
  raise EvilEvents::UnrecognizedSerializationEngineError
30
27
  end
@@ -46,7 +46,7 @@ module EvilEvents::Core::Events
46
46
  #
47
47
  # @since 0.1.0
48
48
  def default_resolver
49
- delegation = -> { EvilEvents::Core::Bootstrap[:config].subscriber.default_delegator }
49
+ delegation = -> { EvilEvents::Core::Bootstrap[:config].settings.subscriber.default_delegator }
50
50
  EvilEvents::Shared::DelegatorResolver.new(delegation)
51
51
  end
52
52
  end
@@ -4,13 +4,19 @@ module EvilEvents
4
4
  # @api public
5
5
  # @since 0.2.0
6
6
  class Plugins
7
+ require_relative 'plugins/oj_engine'
8
+ require_relative 'plugins/ox_engine'
9
+ require_relative 'plugins/mpacker_engine'
10
+
7
11
  # @since 0.3.0
8
12
  extend Shared::ExtensionsMixin
9
13
 
10
- # @since 0.3.0
11
- register_extension(:redis_adapter) { require_relative 'plugins/redis_adapter' }
12
- # @since 0.3.0
13
- register_extension(:sidekiq_adapter) { require_relative 'plugins/sidekiq_adapter' }
14
+ # @since 0.5.0
15
+ register_extension(:oj_engine) { OjEngine.load! }
16
+ # @since 0.5.0
17
+ register_extension(:ox_engine) { OxEngine.load! }
18
+ # @since 0.5.0
19
+ register_extension(:mpacker_engine) { MpackerEngine.load! }
14
20
 
15
21
  class << self
16
22
  # @param plugins [Symbol,Symbol,Symbol,...]
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EvilEvents::Plugins
4
+ # @api private
5
+ # @since 0.5.0
6
+ module MpackerEngine
7
+ class << self
8
+ # @return [void]
9
+ #
10
+ # @api private
11
+ # @since 0.5.0
12
+ def load!
13
+ load_dependencies!
14
+ load_code!
15
+ end
16
+
17
+ private
18
+
19
+ # @return [void]
20
+ #
21
+ # @api private
22
+ # @since 0.5.0
23
+ def load_dependencies!
24
+ require 'msgpack'
25
+ end
26
+
27
+ # @return [void]
28
+ #
29
+ # @api private
30
+ # @since 0.5.0
31
+ def load_code!
32
+ require_relative 'mpacker_engine/config'
33
+ require_relative 'mpacker_engine/mpacker'
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # @api public
4
+ # @since 0.5.0
5
+ class EvilEvents::Core::Config
6
+ setting :serializers do
7
+ setting :msgpack do
8
+ setting :mpacker do
9
+ setting :configurator, ->(engine) {}
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,15 +2,15 @@
2
2
 
3
3
  class EvilEvents::Core::Events::Serializers::MessagePack::Engines
4
4
  # @api private
5
- # @since 0.4.0
5
+ # @since 0.5.0
6
6
  class Mpacker < EvilEvents::Core::Events::Serializers::Base::AbstractEngine
7
7
  # @param config [EvilEvents::Core::Events::Serializers::MessagePack::Config]
8
8
  # @raise [EvilEvents::SerializationEngineError]
9
9
  #
10
10
  # @api private
11
- # @since 0.4.0
11
+ # @since 0.5.0
12
12
  def initialize(config)
13
- configurator = config.mpacker.configurator
13
+ configurator = config.settings.options[:mpacker][:configurator]
14
14
  raise EvilEvents::SerializationEngineError unless configurator.is_a?(Proc)
15
15
  @factory = ::MessagePack::Factory.new.tap { |factory| configurator.call(factory) }
16
16
  end
@@ -18,7 +18,7 @@ class EvilEvents::Core::Events::Serializers::MessagePack::Engines
18
18
  # @param serialization_state [Base::EventSerializationState]
19
19
  # @return [String]
20
20
  #
21
- # @since 0.4.0
21
+ # @since 0.5.0
22
22
  # @api private
23
23
  def dump(serialization_state)
24
24
  packer.pack(
@@ -33,7 +33,7 @@ class EvilEvents::Core::Events::Serializers::MessagePack::Engines
33
33
  # @raise [EvilEvents::SerializationEngineError]
34
34
  # @return [EventSerializationState]
35
35
  #
36
- # @since 0.4.0
36
+ # @since 0.5.0
37
37
  # @api private
38
38
  def load(message)
39
39
  begin
@@ -56,13 +56,13 @@ class EvilEvents::Core::Events::Serializers::MessagePack::Engines
56
56
  # @return [::MessagePack::Factory]
57
57
  #
58
58
  # @api private
59
- # @since 0.4.0
59
+ # @since 0.5.0
60
60
  attr_reader :factory
61
61
 
62
62
  # @return [::MessagePack::Packer]
63
63
  #
64
64
  # @api private
65
- # @since 0.4.0
65
+ # @since 0.5.0
66
66
  def packer
67
67
  factory.packer
68
68
  end
@@ -70,12 +70,12 @@ class EvilEvents::Core::Events::Serializers::MessagePack::Engines
70
70
  # @return [::MessagePack::Unpacker]
71
71
  #
72
72
  # @api private
73
- # @since 0.4.0
73
+ # @since 0.5.0
74
74
  def unpacker
75
75
  factory.unpacker(symbolize_keys: true)
76
76
  end
77
77
  end
78
78
 
79
- # @since 0.4.0
79
+ # @since 0.5.0
80
80
  register(:mpacker, Mpacker)
81
81
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EvilEvents::Plugins
4
+ # @api private
5
+ # @since 0.5.0
6
+ module OjEngine
7
+ class << self
8
+ # @return [void]
9
+ #
10
+ # @api private
11
+ # @since 0.5.0
12
+ def load!
13
+ load_dependencies!
14
+ load_code!
15
+ end
16
+
17
+ private
18
+
19
+ # @return [void]
20
+ #
21
+ # @api private
22
+ # @since 0.5.0
23
+ def load_dependencies!
24
+ require 'oj'
25
+ end
26
+
27
+ # @return [void]
28
+ #
29
+ # @api private
30
+ # @since 0.5.0
31
+ def load_code!
32
+ require_relative 'oj_engine/oj'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EvilEvents::Core::Events::Serializers::JSON::Engines
4
+ # @api private
5
+ # @since 0.5.0
6
+ class Oj < EvilEvents::Core::Events::Serializers::Base::AbstractEngine
7
+ # @param serialization_state [Base::EventSerializationState]
8
+ # @return [String]
9
+ #
10
+ # @since 0.5.0
11
+ # @api private
12
+ def dump(serialization_state)
13
+ ::Oj.dump(
14
+ id: serialization_state.id,
15
+ type: serialization_state.type,
16
+ payload: serialization_state.payload,
17
+ metadata: serialization_state.metadata
18
+ )
19
+ end
20
+
21
+ # @param json_string [String]
22
+ # @raise [EvilEvents::SerializationEngineError]
23
+ # @return [EventSerializationState]
24
+ #
25
+ # @since 0.5.0
26
+ # @api private
27
+ def load(json_string)
28
+ json = ::Oj.load(json_string, symbol_keys: true)
29
+
30
+ restore_serialization_state(
31
+ id: json[:id],
32
+ type: json[:type],
33
+ payload: json[:payload],
34
+ metadata: json[:metadata]
35
+ )
36
+ rescue ::Oj::Error, NoMethodError, TypeError, ArgumentError
37
+ raise EvilEvents::SerializationEngineError
38
+ end
39
+ end
40
+
41
+ # @since 0.5.0
42
+ register(:oj, Oj)
43
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EvilEvents::Plugins
4
+ # @api private
5
+ # @since 0.5.0
6
+ module OxEngine
7
+ class << self
8
+ # @return [void]
9
+ #
10
+ # @api private
11
+ # @since 0.5.0
12
+ def load!
13
+ load_dependencies!
14
+ load_code!
15
+ end
16
+
17
+ private
18
+
19
+ # @return [void]
20
+ #
21
+ # @api private
22
+ # @since 0.5.0
23
+ def load_dependencies!
24
+ require 'ox'
25
+ end
26
+
27
+ # @return [void]
28
+ #
29
+ # @api private
30
+ # @since 0.5.0
31
+ def load_code!
32
+ require_relative 'ox_engine/ox'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -2,12 +2,12 @@
2
2
 
3
3
  class EvilEvents::Core::Events::Serializers::XML::Engines
4
4
  # @api private
5
- # @since 0.4.0
5
+ # @since 0.5.0
6
6
  class Ox < EvilEvents::Core::Events::Serializers::Base::AbstractEngine
7
7
  # @param serialization_state [Base::EventSerializationState]
8
8
  # @return [String]
9
9
  #
10
- # @since 0.4.0
10
+ # @since 0.5.0
11
11
  # @api private
12
12
  def dump(serialization_state)
13
13
  ::Ox.dump(serialization_state)
@@ -17,7 +17,7 @@ class EvilEvents::Core::Events::Serializers::XML::Engines
17
17
  # @raise [EvilEvents::SerializationEngineError]
18
18
  # @return [EventSerializationState]
19
19
  #
20
- # @since 0.4.0
20
+ # @since 0.5.0
21
21
  # @api private
22
22
  def load(xml)
23
23
  ::Ox.parse_obj(xml)
@@ -26,6 +26,6 @@ class EvilEvents::Core::Events::Serializers::XML::Engines
26
26
  end
27
27
  end
28
28
 
29
- # @since 0.4.0
29
+ # @since 0.5.0
30
30
  register(:ox, Ox)
31
31
  end
@@ -4,6 +4,9 @@ module EvilEvents::Shared
4
4
  # @api public
5
5
  # @since 0.1.0
6
6
  class Structure < Dry::Struct
7
+ # NOTE: dry-struct API + dry-initializer API
8
+ input input.strict
9
+
7
10
  class << self
8
11
  # @since 0.1.0
9
12
  alias_method :_native_attribute, :attribute
@@ -16,8 +19,5 @@ module EvilEvents::Shared
16
19
  _native_attribute(key, type)
17
20
  end
18
21
  end
19
-
20
- # NOTE: dry-struct API + dry-initializer API
21
- constructor_type :strict_with_defaults
22
22
  end
23
23
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module EvilEvents
4
4
  # @api public
5
- # @since 0.4.0
6
- VERSION = '0.4.0'
5
+ # @since 0.5.0
6
+ VERSION = '0.5.0'
7
7
  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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rustam Ibragimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-01 00:00:00.000000000 Z
11
+ date: 2018-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads
@@ -30,42 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.12.2
33
+ version: 0.13.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.12.2
40
+ version: 0.13.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dry-struct
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.1
47
+ version: 0.5.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.3.1
55
- - !ruby/object:Gem::Dependency
56
- name: dry-configurable
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 0.7.0
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 0.7.0
54
+ version: 0.5.0
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: dry-container
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -109,33 +95,19 @@ dependencies:
109
95
  - !ruby/object:Gem::Version
110
96
  version: 0.2.0
111
97
  - !ruby/object:Gem::Dependency
112
- name: ox
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: 2.9.2
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: 2.9.2
125
- - !ruby/object:Gem::Dependency
126
- name: msgpack
98
+ name: qonfig
127
99
  requirement: !ruby/object:Gem::Requirement
128
100
  requirements:
129
101
  - - "~>"
130
102
  - !ruby/object:Gem::Version
131
- version: 1.2.4
103
+ version: 0.1.0
132
104
  type: :runtime
133
105
  prerelease: false
134
106
  version_requirements: !ruby/object:Gem::Requirement
135
107
  requirements:
136
108
  - - "~>"
137
109
  - !ruby/object:Gem::Version
138
- version: 1.2.4
110
+ version: 0.1.0
139
111
  - !ruby/object:Gem::Dependency
140
112
  name: coveralls
141
113
  requirement: !ruby/object:Gem::Requirement
@@ -282,8 +254,11 @@ files:
282
254
  - README.md
283
255
  - Rakefile
284
256
  - bin/console
257
+ - bin/rspec
285
258
  - bin/setup
286
259
  - evil_events.gemspec
260
+ - gemfiles/with_native_extensions.gemfile
261
+ - gemfiles/without_native_extensions.gemfile
287
262
  - lib/evil_events.rb
288
263
  - lib/evil_events/application.rb
289
264
  - lib/evil_events/config.rb
@@ -359,14 +334,14 @@ files:
359
334
  - lib/evil_events/core/events/serializers/message_pack.rb
360
335
  - lib/evil_events/core/events/serializers/message_pack/config.rb
361
336
  - lib/evil_events/core/events/serializers/message_pack/engines.rb
362
- - lib/evil_events/core/events/serializers/message_pack/engines/mpacker.rb
337
+ - lib/evil_events/core/events/serializers/message_pack/engines/.keep
363
338
  - lib/evil_events/core/events/serializers/message_pack/factory.rb
364
339
  - lib/evil_events/core/events/serializers/message_pack/packer.rb
365
340
  - lib/evil_events/core/events/serializers/message_pack/unpacker.rb
366
341
  - lib/evil_events/core/events/serializers/xml.rb
367
342
  - lib/evil_events/core/events/serializers/xml/config.rb
368
343
  - lib/evil_events/core/events/serializers/xml/engines.rb
369
- - lib/evil_events/core/events/serializers/xml/engines/ox.rb
344
+ - lib/evil_events/core/events/serializers/xml/engines/.keep
370
345
  - lib/evil_events/core/events/serializers/xml/factory.rb
371
346
  - lib/evil_events/core/events/serializers/xml/packer.rb
372
347
  - lib/evil_events/core/events/serializers/xml/unpacker.rb
@@ -384,8 +359,13 @@ files:
384
359
  - lib/evil_events/error.rb
385
360
  - lib/evil_events/event.rb
386
361
  - lib/evil_events/plugins.rb
387
- - lib/evil_events/plugins/redis_adapter.rb
388
- - lib/evil_events/plugins/sidekiq_adapter.rb
362
+ - lib/evil_events/plugins/mpacker_engine.rb
363
+ - lib/evil_events/plugins/mpacker_engine/config.rb
364
+ - lib/evil_events/plugins/mpacker_engine/mpacker.rb
365
+ - lib/evil_events/plugins/oj_engine.rb
366
+ - lib/evil_events/plugins/oj_engine/oj.rb
367
+ - lib/evil_events/plugins/ox_engine.rb
368
+ - lib/evil_events/plugins/ox_engine/ox.rb
389
369
  - lib/evil_events/serializer.rb
390
370
  - lib/evil_events/shared.rb
391
371
  - lib/evil_events/shared/any_config.rb
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api public
4
- # @since 0.3.0
5
- module EvilEvents::RedisAdapter
6
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # @api public
4
- # @since 0.3.0
5
- module EvilEvents::SidekiqAdapter
6
- end