wet-command_bus 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +4 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/wet/command_bus.rb +30 -0
- data/lib/wet/command_bus/version.rb +5 -0
- data/wet-command_bus.gemspec +26 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 62d9843340ef7d32403570a92a743755b076f8bb
|
4
|
+
data.tar.gz: 4fc0afb881d2dcb5a5b51ddcdf97ae0af53de0d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ea3bd3a9dfb45c44e1df66b901f40e23b0be59f846518106b9dbd8a89c539eb4c5d1d1d2dfc22a5cef62226fd4cd812ee37f1f6a034da9218cd93d34f3817ff
|
7
|
+
data.tar.gz: 8fb81565b70e79f3897870acd6847052c6169582ae333e3f700b7fbd203dff356065f9553ad125f23ea9197f913260812630db45cbde8a8f2b96b203883ad4e3
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# CommandBus
|
2
|
+
|
3
|
+
> Command Pattern - decoupling what is done from who does it.
|
4
|
+
|
5
|
+
|
6
|
+
Usage:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
require 'wet/command_bus'
|
10
|
+
|
11
|
+
command_bus = Wet::CommandBus.new
|
12
|
+
register = command_bus.method(:register)
|
13
|
+
|
14
|
+
{ FooCommand => FooService.new(event_store: event_store).method(:foo),
|
15
|
+
BarCommand => BarService.new,
|
16
|
+
}.map(&:register)
|
17
|
+
|
18
|
+
|
19
|
+
command_bus.(FooCommand.new)
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
Now think how that makes your system simpler and use it or forget and move on.
|
24
|
+
|
25
|
+
## About
|
26
|
+
|
27
|
+
<img src="http://arkency.com/images/arkency.png" alt="Arkency" width="20%" align="left" />
|
28
|
+
|
29
|
+
Rails Event Store is funded and maintained by Arkency. Check out our other [open-source projects](https://github.com/arkency).
|
30
|
+
|
31
|
+
You can also [hire us](http://arkency.com) or [read our blog](http://blog.arkency.com).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "command_bus"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'wet/command_bus/version'
|
2
|
+
require 'thread_safe'
|
3
|
+
|
4
|
+
module Wet
|
5
|
+
class CommandBus
|
6
|
+
UnregisteredHandler = Class.new(StandardError)
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@handlers =
|
10
|
+
ThreadSafe::Cache.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def register(klass, handler)
|
14
|
+
handlers[klass] = handler
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(command)
|
18
|
+
handlers
|
19
|
+
.fetch(command.class) { raise UnregisteredHandler.new(message(command)) }
|
20
|
+
.(command)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
attr_reader :handlers
|
25
|
+
|
26
|
+
def message(command)
|
27
|
+
"Missing handler for #{command.class}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wet/command_bus/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wet-command_bus"
|
8
|
+
spec.version = Wet::CommandBus::VERSION
|
9
|
+
spec.authors = ["Arkency"]
|
10
|
+
spec.email = ["dev@arkency.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Command Pattern - decoupling what is done from who does it.}
|
13
|
+
spec.homepage = "https://github.com/wetrb/wet-command_bus"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "thread_safe"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.4.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wet-command_bus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arkency
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thread_safe
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.4.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.4.0
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- dev@arkency.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- CHANGELOG.md
|
78
|
+
- Gemfile
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- bin/console
|
82
|
+
- bin/setup
|
83
|
+
- lib/wet/command_bus.rb
|
84
|
+
- lib/wet/command_bus/version.rb
|
85
|
+
- wet-command_bus.gemspec
|
86
|
+
homepage: https://github.com/wetrb/wet-command_bus
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.4.5
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Command Pattern - decoupling what is done from who does it.
|
110
|
+
test_files: []
|
111
|
+
has_rdoc:
|