arkency-command_bus 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fa44d11c3221c6935f1e35ce432ba3a1f7a1fc57
4
+ data.tar.gz: 1f792ef3941cdbf96f0e21add8df0851688f3041
5
+ SHA512:
6
+ metadata.gz: af938c22d708124a7b64322bfdd0b7c6753d09065c8b74e8a441df967332fd8ca1bf64033be4234e0ef168894f82f7917b1adda1cc5e575bee131ea690a1a645
7
+ data.tar.gz: 97e7789e2e71683f605a8d5ef1ea84a9aa95c1d4e6d9050e8b4d7b94662e25803cc7847eb0a6fdc1064deb0f425e55c9857b59413f05b9361ea2545e9bcd311d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,18 @@
1
+ ### 0.4.0
2
+
3
+ * Find home under Arkency organization.
4
+ * Rename namespace for less future confusion.
5
+ * Convenience top-level alias.
6
+
7
+ ### 0.3.0
8
+
9
+ * Make sure there is only one handler per command registered.
10
+
11
+ ### 0.2.0
12
+
13
+ * Rename and namespacing under `Wet` in order to release on RubyGems.
14
+ * Added license.
15
+
16
+ ### 0.1.0
17
+
18
+ * Initial release.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in command_bus.gemspec
4
+ gemspec
@@ -0,0 +1,43 @@
1
+ # Command Bus
2
+
3
+ > Command Pattern - decoupling what is done from who does it.
4
+
5
+ ## Installation
6
+
7
+ Notice this gem is namespaced.
8
+
9
+ gem install arkency-command_bus
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ require 'arkency/command_bus'
15
+
16
+ command_bus = Arkency::CommandBus.new
17
+ register = command_bus.method(:register)
18
+
19
+ { FooCommand => FooService.new(event_store: event_store).method(:foo),
20
+ BarCommand => BarService.new,
21
+ }.map(&:register)
22
+
23
+
24
+ command_bus.(FooCommand.new)
25
+
26
+ ```
27
+
28
+
29
+ ## Convenience alias
30
+
31
+ ```ruby
32
+ require 'arkency/command_bus/alias'
33
+ ```
34
+
35
+ From now on you can use top-level `::CommandBus`.
36
+
37
+ ## About
38
+
39
+ <img src="http://arkency.com/images/arkency.png" alt="Arkency" width="20%" align="left" />
40
+
41
+ Command Bus is funded and maintained by Arkency. Check out our other [open-source projects](https://github.com/arkency).
42
+
43
+ You can also [hire us](http://arkency.com) or [read our blog](http://blog.arkency.com).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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 'arkency/command_bus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "arkency-command_bus"
8
+ spec.version = Arkency::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/arkency/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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "arkency/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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ require 'arkency/command_bus/version'
2
+ require 'thread_safe'
3
+
4
+ module Arkency
5
+ class CommandBus
6
+ UnregisteredHandler = Class.new(StandardError)
7
+ MultipleHandlers = Class.new(StandardError)
8
+
9
+ def initialize
10
+ @handlers =
11
+ ThreadSafe::Cache.new
12
+ end
13
+
14
+ def register(klass, handler)
15
+ raise MultipleHandlers.new("Multiple handlers not allowed for #{klass}") if handlers[klass]
16
+ handlers[klass] = handler
17
+ end
18
+
19
+ def call(command)
20
+ handlers
21
+ .fetch(command.class) { raise UnregisteredHandler.new("Missing handler for #{command.class}") }
22
+ .(command)
23
+ end
24
+
25
+ private
26
+ attr_reader :handlers
27
+ end
28
+ end
@@ -0,0 +1,2 @@
1
+ raise StandardError.new('CommandBus has been already defined, giving up.') if defined?(::CommandBus)
2
+ ::CommandBus = Arkency::CommandBus
@@ -0,0 +1,5 @@
1
+ module Arkency
2
+ class CommandBus
3
+ VERSION = '0.4.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: arkency-command_bus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Arkency
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-01 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
+ - arkency-command_bus.gemspec
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/arkency/command_bus.rb
85
+ - lib/arkency/command_bus/alias.rb
86
+ - lib/arkency/command_bus/version.rb
87
+ homepage: https://github.com/arkency/command_bus
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.5
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Command Pattern - decoupling what is done from who does it.
111
+ test_files: []
112
+ has_rdoc: