command_bus 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 379da1328a8d212d203bf9914b0ac8b020e2c4f4
4
+ data.tar.gz: 0abac4ad93d08ff4efd81af5ef9496c07aa746c8
5
+ SHA512:
6
+ metadata.gz: 756f8464657542fa31c1c2a59e7f5f56beab782a6b0293678deffa740bbc64c5619e8d1b5a435b4f04e3ba8a3a9d163dfb9787af4c0a91745fad87b46e50f9ee
7
+ data.tar.gz: 090b15bacc75b3e83003ad954050e8ac76316e72a07148171fb5cd7ef5b3a6b00d1cfdb664e3ea55f19ea405817a17a8eb817b95c29351d72d592db218862718
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # changes
2
+
3
+ ## version 0.1.0
4
+
5
+ * configure the command bus to get an instance
6
+ * load handler in root path
7
+ * will instantiate a class and call execute on it
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Louis P. Salin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Simple command bus
2
+
3
+ Send it a command and it will search the root path for a command handler that can execute that command.
4
+
5
+ ## Convention
6
+
7
+ Commands are typical ruby symbols
8
+ Command handlers must be classes name after the command and must end with 'CommandHandler'. They must also be in a file named after the command that must end with 'command_handler'
9
+
10
+ ## Example
11
+ ```ruby
12
+ bus = CommandBus.config do |config|
13
+ config.root = 'lib/command_handlers'
14
+ end
15
+
16
+ bus.execute(:create_new_account)
17
+ ```
18
+
19
+ In this example, command_bus will require 'lib/command_handlers/create_new_account_command_handler' and, instantiate the CreateNewAccountCommandHandler and call execute on it.
@@ -0,0 +1,41 @@
1
+ require 'active_support/inflector'
2
+
3
+ class CommandBus
4
+ CommandBusConfig = Struct.new(:root)
5
+
6
+ class << self
7
+ def config
8
+ c = CommandBusConfig.new
9
+ yield c
10
+ self.new c
11
+ end
12
+ end
13
+
14
+ def root
15
+ @config.root
16
+ end
17
+
18
+ def execute(cmd)
19
+ handler_class = load_handler(cmd)
20
+ handler_class.new.execute
21
+ end
22
+
23
+ private
24
+
25
+ def initialize(config)
26
+ @config = config
27
+ end
28
+
29
+ def load_handler(cmd)
30
+ require_handler(cmd)
31
+
32
+ handler_name = "#{cmd.to_s}_command_handler"
33
+ handler_name.camelize.constantize
34
+ end
35
+
36
+ def require_handler(cmd)
37
+ path = "./#{@config.root}/#{cmd}_command_handler"
38
+ require path
39
+ end
40
+ end
41
+
@@ -0,0 +1,3 @@
1
+ class CommandBus
2
+ Version = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: command_bus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Louis Salin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Execute a command and the command bus will look up the proper handler
28
+ class automatically and execute it
29
+ email:
30
+ - louis.phil@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - lib/command_bus.rb
36
+ - lib/command_bus/version.rb
37
+ - LICENSE
38
+ - README.md
39
+ - CHANGELOG.md
40
+ homepage: http://github.com/louissalin/command_bus
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.0.0.rc.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: A simple command bus
64
+ test_files: []