arkency-command_bus 0.4.0 → 0.4.1
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 +5 -5
- data/CHANGELOG.md +4 -0
- data/README.md +66 -2
- data/arkency-command_bus.gemspec +2 -2
- data/lib/arkency/command_bus/version.rb +1 -1
- data/lib/arkency/command_bus.rb +2 -2
- metadata +8 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4d3914780d62cc5664255fe108ad8cb62059459fe54303516e93ad3bcede3341
|
4
|
+
data.tar.gz: e9104088783aa7eace84160d00f0579150f57a52c00a98c3407c94e0f23903a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06ef9b01acafff9de818662d38361dfe88efb012998411c1b7b1bc2baa8b175e713bd5801edf1f3f8db4fc9b9eb8dbb347eaa553cd805dd6c16bab480cb4c5be
|
7
|
+
data.tar.gz: 38c5c711002e476a25552734855c7ca8feae249ea2d6a4923c6f70579a3eaf97da31a1a4eb7c799558be937345aa99c9c12418d0281690969daddac09066991e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -18,13 +18,67 @@ register = command_bus.method(:register)
|
|
18
18
|
|
19
19
|
{ FooCommand => FooService.new(event_store: event_store).method(:foo),
|
20
20
|
BarCommand => BarService.new,
|
21
|
-
}.map(
|
21
|
+
}.map(®ister)
|
22
22
|
|
23
23
|
|
24
24
|
command_bus.(FooCommand.new)
|
25
25
|
|
26
26
|
```
|
27
27
|
|
28
|
+
### New instance of a service for every command
|
29
|
+
|
30
|
+
If need a new instance of a service every time it is called with a command or you want to lazily load the responsible services, you can just use `Proc` during registration.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
command_bus = Arkency::CommandBus.new
|
34
|
+
command_bus.register(FooCommand, -> (foo_cmd) { FooService.new(event_store: event_store).foo(foo_cmd) })
|
35
|
+
command_bus.register(BarCommand, -> (bar_cmd) { BarService.new.call(bar_cmd) })
|
36
|
+
```
|
37
|
+
|
38
|
+
### Working with Rails development mode
|
39
|
+
|
40
|
+
In Rails `development` mode when you change a registered class, it is reloaded, and a new class with same name is constructed.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
a = User
|
44
|
+
a.object_id
|
45
|
+
# => 40737760
|
46
|
+
|
47
|
+
reload!
|
48
|
+
# Reloading...
|
49
|
+
|
50
|
+
b = User
|
51
|
+
b.object_id
|
52
|
+
# => 48425300
|
53
|
+
|
54
|
+
h = {a => 1, b => 2}
|
55
|
+
h[User]
|
56
|
+
# => 2
|
57
|
+
|
58
|
+
a == b
|
59
|
+
# => false
|
60
|
+
```
|
61
|
+
|
62
|
+
so your `Hash` with mapping from command class to service may not find the new version of reloaded class.
|
63
|
+
|
64
|
+
To workaround this problem you can use [`to_prepare`](http://api.rubyonrails.org/classes/Rails/Railtie/Configuration.html#method-i-to_prepare) callback which is executed before every code reload in development, and once in production.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
config.to_prepare do
|
68
|
+
config.command_bus = Arkency::CommandBus.new
|
69
|
+
register = command_bus.method(:register)
|
70
|
+
|
71
|
+
{ FooCommand => FooService.new(event_store: event_store).method(:foo),
|
72
|
+
BarCommand => BarService.new,
|
73
|
+
}.map(®ister)
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
and call it with
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
Rails.configuration.command_bus.call(FooCommand.new)
|
81
|
+
```
|
28
82
|
|
29
83
|
## Convenience alias
|
30
84
|
|
@@ -32,7 +86,7 @@ command_bus.(FooCommand.new)
|
|
32
86
|
require 'arkency/command_bus/alias'
|
33
87
|
```
|
34
88
|
|
35
|
-
From now on you can use top-level
|
89
|
+
From now on you can use top-level `CommandBus` instead of `Arkency::CommandBus`.
|
36
90
|
|
37
91
|
## About
|
38
92
|
|
@@ -41,3 +95,13 @@ From now on you can use top-level `::CommandBus`.
|
|
41
95
|
Command Bus is funded and maintained by Arkency. Check out our other [open-source projects](https://github.com/arkency).
|
42
96
|
|
43
97
|
You can also [hire us](http://arkency.com) or [read our blog](http://blog.arkency.com).
|
98
|
+
|
99
|
+
## Learn more about DDD & Event Sourcing
|
100
|
+
|
101
|
+
Check our **Rails + Domain Driven Design Workshop** [more details](http://blog.arkency.com/ddd-training/).
|
102
|
+
|
103
|
+
Why You should attend? Robert has explained this in [this blogpost](http://blog.arkency.com/2016/12/why-would-you-even-want-to-listen-about-ddd/).
|
104
|
+
|
105
|
+
Next edition will be held in **September 2017** (Thursday & Friday) in Berlin, Germany.
|
106
|
+
Workshop will be held in English.
|
107
|
+
|
data/arkency-command_bus.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "
|
21
|
+
spec.add_dependency "concurrent-ruby"
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler"
|
23
|
+
spec.add_development_dependency "bundler"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.4.0"
|
26
26
|
end
|
data/lib/arkency/command_bus.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'arkency/command_bus/version'
|
2
|
-
require '
|
2
|
+
require 'concurrent/map'
|
3
3
|
|
4
4
|
module Arkency
|
5
5
|
class CommandBus
|
@@ -8,7 +8,7 @@ module Arkency
|
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@handlers =
|
11
|
-
|
11
|
+
Concurrent::Map.new
|
12
12
|
end
|
13
13
|
|
14
14
|
def register(klass, handler)
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arkency-command_bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: concurrent-ruby
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
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: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,10 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
|
107
|
-
rubygems_version: 2.4.5
|
106
|
+
rubygems_version: 3.2.32
|
108
107
|
signing_key:
|
109
108
|
specification_version: 4
|
110
109
|
summary: Command Pattern - decoupling what is done from who does it.
|
111
110
|
test_files: []
|
112
|
-
has_rdoc:
|