aggregate_root 2.19.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8960b3ed56b2a2a0a87bcc19d21a9b8c3d5775ab3e110d0dafa2e9bb9bbae54
4
- data.tar.gz: 87ea0f825d91cdc8fb0bd4c47924a47b5fef465c9034d3a6889b8132668b85bf
3
+ metadata.gz: e887ac1f5bda1b99e0e5c811ba763f9ba9c8bfdf65ffad97f855b3409a77dfe7
4
+ data.tar.gz: a32c4c968a6b1f2cb909f90b06a224c396da701a96a871194798250de8a1fa67
5
5
  SHA512:
6
- metadata.gz: c9ab03ee7df3bc9090c5d1ce2f190b4f6519946c8adbfe66ceb34e0d97ae374aa6f0d354d4b57570c66a28f361dfe4184d37f6b9231f3e65cc1dcb6f5f5cf6aa
7
- data.tar.gz: 4701c2be5484ba2e58609adb0d885c317f73719af5edb6284527cb22b9e6d58a9a5970e07ec0399b91f49bb237902e6e14f4fbfab1ec48cba46533683ec49a58
6
+ metadata.gz: dfa906dd122a959b0f4dd016442ef5c1f65530fe1533461f54654f16b2b339f97b79c16579a96dc91cea560f5de42b02c2ef47eea235bbddc880743f1a283c63
7
+ data.tar.gz: 507c0ab80f3c52593f877cc9adfaf83e9701426dd370add27a5f645c1a383d67b2a1c782321e0a04a4051e9572d6b14e6af4ebe0c916fb6a37532392b82161f8
@@ -2,52 +2,32 @@
2
2
 
3
3
  module AggregateRoot
4
4
  MissingHandler = Class.new(StandardError)
5
+ NullHandler = Proc.new {}
5
6
 
6
7
  class DefaultApplyStrategy
7
- DEPRECATION_MESSAGE = <<~EOW
8
- Handling events via apply_* method naming convention is deprecated and will be removed in the next major release.
9
-
10
- Use the on DSL instead:
11
-
12
- on %s do |event|
13
- # your code
14
- end
15
- EOW
16
- private_constant :DEPRECATION_MESSAGE
17
-
18
8
  def initialize(strict: true)
19
9
  @strict = strict
20
10
  end
21
11
 
22
12
  def call(aggregate, event)
23
- name = handler_name(aggregate, event)
24
- if aggregate.respond_to?(name, true)
25
- aggregate.method(name).call(event)
26
- else
27
- raise MissingHandler.new("Missing handler method #{name} on aggregate #{aggregate.class}") if strict
28
- end
13
+ on_handler(aggregate, event.event_type)[event]
29
14
  end
30
15
 
31
16
  private
32
17
 
33
- def handler_name(aggregate, event)
34
- on_dsl_handler_name(aggregate, event.event_type) || apply_handler_name(aggregate, event.event_type)
18
+ def on_handler(aggregate, event_type)
19
+ on_method_name = aggregate.class.on_methods.fetch(event_type)
20
+ aggregate.method(on_method_name)
21
+ rescue KeyError, NoMethodError
22
+ missing_handler(aggregate, event_type)
35
23
  end
36
24
 
37
- def on_dsl_handler_name(aggregate, event_type)
38
- aggregate.class.on_methods[event_type] if aggregate.class.respond_to?(:on_methods)
39
- end
40
-
41
- def apply_handler_name(aggregate, event_type)
42
- name = "apply_#{Transform.to_snake_case(event_type(event_type))}"
43
- if aggregate.respond_to?(name, true)
44
- warn DEPRECATION_MESSAGE % event_type
25
+ def missing_handler(aggregate, event_type)
26
+ if strict
27
+ lambda { |event| raise MissingHandler.new("Missing handler method on aggregate #{aggregate.class} for #{event_type}") }
28
+ else
29
+ NullHandler
45
30
  end
46
- name
47
- end
48
-
49
- def event_type(event_type)
50
- event_type.split(/::|\./).last
51
31
  end
52
32
 
53
33
  attr_reader :strict, :on_methods
@@ -2,7 +2,7 @@
2
2
 
3
3
  module AggregateRoot
4
4
  class Repository
5
- def initialize(event_store = default_event_store)
5
+ def initialize(event_store)
6
6
  @event_store = event_store
7
7
  end
8
8
 
@@ -31,13 +31,5 @@ module AggregateRoot
31
31
  private
32
32
 
33
33
  attr_reader :event_store
34
-
35
- def default_event_store
36
- warn <<~EOW
37
- DEPRECATION WARNING: Calling `AggregateRoot::Repository.new` without an event store argument relies on `AggregateRoot::Configuration` which is deprecated and will be removed in the next major release.
38
- Use `AggregateRoot::Repository.new(event_store)` with explicit event store injection instead.
39
- EOW
40
- AggregateRoot.configuration.default_event_store
41
- end
42
34
  end
43
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AggregateRoot
4
- VERSION = "2.19.1"
4
+ VERSION = "3.0.0"
5
5
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "aggregate_root/version"
4
- require_relative "aggregate_root/configuration"
5
- require_relative "aggregate_root/transform"
6
4
  require_relative "aggregate_root/default_apply_strategy"
7
5
  require_relative "aggregate_root/repository"
8
6
  require_relative "aggregate_root/instrumented_repository"
@@ -78,24 +76,6 @@ module AggregateRoot
78
76
  end
79
77
  end
80
78
 
81
- def self.with_default_apply_strategy
82
- Module.new do
83
- def self.included(host_class)
84
- warn <<~EOW
85
- Please replace include AggregateRoot.with_default_apply_strategy with include AggregateRoot
86
- EOW
87
- host_class.include AggregateRoot
88
- end
89
- end
90
- end
91
-
92
- def self.with_strategy(strategy)
93
- warn <<~EOW
94
- Please replace include AggregateRoot.with_strategy(...) with include AggregateRoot.with(strategy: ...)
95
- EOW
96
- with(strategy: strategy)
97
- end
98
-
99
79
  def self.with(strategy: -> { DefaultApplyStrategy.new }, event_type_resolver: ->(value) { value.to_s })
100
80
  Module.new do
101
81
  define_singleton_method :included do |host_class|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aggregate_root
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.19.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkency
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 2.19.1
18
+ version: 3.0.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 2.19.1
25
+ version: 3.0.0
26
26
  email: dev@arkency.com
27
27
  executables: []
28
28
  extensions: []
@@ -31,13 +31,11 @@ extra_rdoc_files:
31
31
  files:
32
32
  - README.md
33
33
  - lib/aggregate_root.rb
34
- - lib/aggregate_root/configuration.rb
35
34
  - lib/aggregate_root/default_apply_strategy.rb
36
35
  - lib/aggregate_root/instrumented_apply_strategy.rb
37
36
  - lib/aggregate_root/instrumented_repository.rb
38
37
  - lib/aggregate_root/repository.rb
39
38
  - lib/aggregate_root/snapshot_repository.rb
40
- - lib/aggregate_root/transform.rb
41
39
  - lib/aggregate_root/version.rb
42
40
  homepage: https://railseventstore.org
43
41
  licenses:
@@ -62,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
60
  - !ruby/object:Gem::Version
63
61
  version: '0'
64
62
  requirements: []
65
- rubygems_version: 4.0.6
63
+ rubygems_version: 3.7.1
66
64
  specification_version: 4
67
65
  summary: Event sourced aggregate root implementation for RubyEventStore
68
66
  test_files: []
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AggregateRoot
4
- class << self
5
- attr_accessor :configuration
6
- end
7
-
8
- def self.configure
9
- warn <<~EOW
10
- DEPRECATION WARNING: `AggregateRoot.configure` and `AggregateRoot::Configuration` are deprecated and will be removed in the next major release.
11
- Use `AggregateRoot::Repository.new(event_store)` with explicit event store injection instead.
12
- EOW
13
- self.configuration ||= Configuration.new
14
- yield(configuration)
15
- end
16
-
17
- class Configuration
18
- attr_accessor :default_event_store
19
- end
20
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AggregateRoot
4
- class Transform
5
- def self.to_snake_case(name)
6
- name.gsub(/([A-Z])([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
7
- end
8
- end
9
- end