aggregate_root 2.19.2 → 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: a981cffad71bcec9a31feb1dd5380b28cfd84d85492eb8514f7170ebf6f39a87
4
- data.tar.gz: 7021c52bc34f625b674fd54cd63e6fa3d76d01c5c9deb6c8c402bc30551c24ad
3
+ metadata.gz: e887ac1f5bda1b99e0e5c811ba763f9ba9c8bfdf65ffad97f855b3409a77dfe7
4
+ data.tar.gz: a32c4c968a6b1f2cb909f90b06a224c396da701a96a871194798250de8a1fa67
5
5
  SHA512:
6
- metadata.gz: 6130d6ab8071b2a0a33f0cd80e09be49cf8529eb816f03dfbc66167a1166724d3dc8371fa59584e11bb9766a11ad5464bcdc4a167640b450ff739b615e540e3c
7
- data.tar.gz: b15afa9d209eba616e46c4fc317faf498e9a6e749c31c62f27c74b2c1eef43c985936706dd35567c00942f7993406dcda34080c31690a25ac4216b8936ff56d9
6
+ metadata.gz: dfa906dd122a959b0f4dd016442ef5c1f65530fe1533461f54654f16b2b339f97b79c16579a96dc91cea560f5de42b02c2ef47eea235bbddc880743f1a283c63
7
+ data.tar.gz: 507c0ab80f3c52593f877cc9adfaf83e9701426dd370add27a5f645c1a383d67b2a1c782321e0a04a4051e9572d6b14e6af4ebe0c916fb6a37532392b82161f8
@@ -2,55 +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
- RubyEventStore::Deprecations.warn(
45
- :"apply_naming_convention_#{event_type}",
46
- message: DEPRECATION_MESSAGE % event_type,
47
- )
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
48
30
  end
49
- name
50
- end
51
-
52
- def event_type(event_type)
53
- event_type.split(/::|\./).last
54
31
  end
55
32
 
56
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,9 +31,5 @@ module AggregateRoot
31
31
  private
32
32
 
33
33
  attr_reader :event_store
34
-
35
- def default_event_store
36
- AggregateRoot.configuration.default_event_store
37
- end
38
34
  end
39
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AggregateRoot
4
- VERSION = "2.19.2"
4
+ VERSION = "3.0.0"
5
5
  end
@@ -1,9 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "ruby_event_store/deprecations"
4
3
  require_relative "aggregate_root/version"
5
- require_relative "aggregate_root/configuration"
6
- require_relative "aggregate_root/transform"
7
4
  require_relative "aggregate_root/default_apply_strategy"
8
5
  require_relative "aggregate_root/repository"
9
6
  require_relative "aggregate_root/instrumented_repository"
@@ -79,18 +76,6 @@ module AggregateRoot
79
76
  end
80
77
  end
81
78
 
82
- def self.with_default_apply_strategy
83
- Module.new do
84
- def self.included(host_class)
85
- host_class.include AggregateRoot
86
- end
87
- end
88
- end
89
-
90
- def self.with_strategy(strategy)
91
- with(strategy: strategy)
92
- end
93
-
94
79
  def self.with(strategy: -> { DefaultApplyStrategy.new }, event_type_resolver: ->(value) { value.to_s })
95
80
  Module.new do
96
81
  define_singleton_method :included do |host_class|
@@ -112,5 +97,3 @@ module AggregateRoot
112
97
  host_class.include with
113
98
  end
114
99
  end
115
-
116
- require_relative "aggregate_root/deprecated"
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.2
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.2
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.2
25
+ version: 3.0.0
26
26
  email: dev@arkency.com
27
27
  executables: []
28
28
  extensions: []
@@ -31,14 +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
- - lib/aggregate_root/deprecated.rb
37
35
  - lib/aggregate_root/instrumented_apply_strategy.rb
38
36
  - lib/aggregate_root/instrumented_repository.rb
39
37
  - lib/aggregate_root/repository.rb
40
38
  - lib/aggregate_root/snapshot_repository.rb
41
- - lib/aggregate_root/transform.rb
42
39
  - lib/aggregate_root/version.rb
43
40
  homepage: https://railseventstore.org
44
41
  licenses:
@@ -63,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
60
  - !ruby/object:Gem::Version
64
61
  version: '0'
65
62
  requirements: []
66
- rubygems_version: 4.0.10
63
+ rubygems_version: 3.7.1
67
64
  specification_version: 4
68
65
  summary: Event sourced aggregate root implementation for RubyEventStore
69
66
  test_files: []
@@ -1,16 +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
- self.configuration ||= Configuration.new
10
- yield(configuration)
11
- end
12
-
13
- class Configuration
14
- attr_accessor :default_event_store
15
- end
16
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AggregateRoot
4
- RubyEventStore::Deprecations.register(
5
- :with_default_apply_strategy,
6
- "Please replace include AggregateRoot.with_default_apply_strategy with include AggregateRoot",
7
- )
8
- RubyEventStore::Deprecations.deprecate_class_method(
9
- AggregateRoot,
10
- :with_default_apply_strategy,
11
- key: :with_default_apply_strategy,
12
- )
13
-
14
- RubyEventStore::Deprecations.register(
15
- :with_strategy,
16
- "Please replace include AggregateRoot.with_strategy(...) with include AggregateRoot.with(strategy: ...)",
17
- )
18
- RubyEventStore::Deprecations.deprecate_class_method(AggregateRoot, :with_strategy, key: :with_strategy)
19
-
20
- RubyEventStore::Deprecations.register(
21
- :aggregate_root_configure,
22
- "`AggregateRoot.configure` and `AggregateRoot::Configuration` are deprecated and will be removed in the next major release.\n" \
23
- "Use `AggregateRoot::Repository.new(event_store)` with explicit event store injection instead.",
24
- )
25
- RubyEventStore::Deprecations.deprecate_class_method(AggregateRoot, :configure, key: :aggregate_root_configure)
26
-
27
- RubyEventStore::Deprecations.register(
28
- :repository_default_event_store,
29
- "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.\n" \
30
- "Use `AggregateRoot::Repository.new(event_store)` with explicit event store injection instead.",
31
- )
32
- RubyEventStore::Deprecations.deprecate(Repository, :default_event_store, key: :repository_default_event_store)
33
- 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