chickadee 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chickadee/dispatcher.rb +9 -3
- data/lib/chickadee/requests/command.rb +4 -1
- data/lib/chickadee/requests/event.rb +4 -1
- data/lib/chickadee/requests/query.rb +4 -1
- data/lib/chickadee/requests/request_type.rb +23 -0
- data/lib/chickadee/version.rb +1 -1
- data/lib/chickadee.rb +1 -1
- data/spec/dispatcher_spec.rb +42 -0
- data/spec/requests/command_spec.rb +4 -7
- data/spec/requests/event_spec.rb +4 -7
- data/spec/requests/query_spec.rb +4 -7
- metadata +4 -2
- data/lib/chickadee/requests/request.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6454dba340dc5b38f51086c1156a2476c0eb1d43
|
4
|
+
data.tar.gz: 6f38fb7fb6819284b47d1331a172470dc47654a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb440f384f0151d7fc2f9e75d707d70a85db83a981330e536458cad7cf3b19bfcf6c698fcff5e9070704566ea844921bf9b52a13a4be967dd9fcbbaf811f7cc5
|
7
|
+
data.tar.gz: da8297ba59d695926bcfe2b518f9f6bdcade6ab80025856e313471190b5627ab25fb012b96b81a4638d0df59458893a82ab3854abc22feaaa4d349648601e049
|
data/lib/chickadee/dispatcher.rb
CHANGED
@@ -19,12 +19,18 @@ module Chickadee
|
|
19
19
|
@container.register(*args)
|
20
20
|
end
|
21
21
|
|
22
|
-
def map(
|
23
|
-
|
22
|
+
def map(request_class, *handlers)
|
23
|
+
return map_command(request_class, *handlers) if request_class.type.command?
|
24
|
+
return map_query(request_class, *handlers) if request_class.type.query?
|
25
|
+
return map_event(request_class, *handlers) if request_class.type.event?
|
26
|
+
raise(DispatcherError, "Unrecognized request type: #{request_class}")
|
24
27
|
end
|
25
28
|
|
26
29
|
def dispatch(request)
|
27
|
-
|
30
|
+
return dispatch_command(request) if request.class.type.command?
|
31
|
+
return dispatch_query(request) if request.class.type.query?
|
32
|
+
return dispatch_event(request) if request.class.type.event?
|
33
|
+
raise(DispatcherError, "Unrecognized request type: #{request.class}")
|
28
34
|
end
|
29
35
|
|
30
36
|
private
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Chickadee
|
2
|
+
class RequestType
|
3
|
+
def initialize(type)
|
4
|
+
@type = type
|
5
|
+
end
|
6
|
+
|
7
|
+
def query?
|
8
|
+
@type == :query
|
9
|
+
end
|
10
|
+
|
11
|
+
def command?
|
12
|
+
@type == :command
|
13
|
+
end
|
14
|
+
|
15
|
+
def event?
|
16
|
+
@type == :event
|
17
|
+
end
|
18
|
+
|
19
|
+
def match?(t)
|
20
|
+
t == @type
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/chickadee/version.rb
CHANGED
data/lib/chickadee.rb
CHANGED
@@ -3,7 +3,7 @@ require 'chickadee/version'
|
|
3
3
|
require 'chickadee/exceptions'
|
4
4
|
require 'chickadee/container'
|
5
5
|
require 'chickadee/handler'
|
6
|
-
require 'chickadee/requests/
|
6
|
+
require 'chickadee/requests/request_type'
|
7
7
|
require 'chickadee/requests/command'
|
8
8
|
require 'chickadee/requests/query'
|
9
9
|
require 'chickadee/requests/event'
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'chickadee'
|
3
|
+
|
4
|
+
describe Chickadee::Dispatcher do
|
5
|
+
it 'can dispatch a command' do
|
6
|
+
handler = stub(:handle => 'handler response')
|
7
|
+
command = Chickadee::Command.new
|
8
|
+
dispatcher = new_dispatcher
|
9
|
+
|
10
|
+
dispatcher.register(:handler, handler, :as => :instance)
|
11
|
+
dispatcher.map(Chickadee::Command, :handler)
|
12
|
+
|
13
|
+
handler.expects(:handle).once
|
14
|
+
dispatcher.dispatch(command).must_be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can dispatch a query' do
|
18
|
+
handler = stub(:handle => 'handler response')
|
19
|
+
query = Chickadee::Query.new
|
20
|
+
dispatcher = new_dispatcher
|
21
|
+
|
22
|
+
dispatcher.register(:handler, handler, :as => :instance)
|
23
|
+
dispatcher.map(Chickadee::Query, :handler)
|
24
|
+
dispatcher.dispatch(query).must_equal('handler response')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can dispatch an event' do
|
28
|
+
handler = stub(:handle => 'handler response')
|
29
|
+
event = Chickadee::Event.new
|
30
|
+
dispatcher = new_dispatcher
|
31
|
+
|
32
|
+
dispatcher.register(:handler, handler, :as => :instance)
|
33
|
+
dispatcher.map(Chickadee::Event, :handler)
|
34
|
+
|
35
|
+
handler.expects(:handle).once
|
36
|
+
dispatcher.dispatch(event).must_be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def new_dispatcher
|
40
|
+
Chickadee::Dispatcher.new
|
41
|
+
end
|
42
|
+
end
|
@@ -2,11 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require 'chickadee'
|
3
3
|
|
4
4
|
describe Chickadee::Command do
|
5
|
-
it {
|
6
|
-
it {
|
7
|
-
it {
|
8
|
-
|
9
|
-
def new_query
|
10
|
-
Chickadee::Command.new
|
11
|
-
end
|
5
|
+
it { Chickadee::Command.type.query?.must_equal(false) }
|
6
|
+
it { Chickadee::Command.type.command?.must_equal(true) }
|
7
|
+
it { Chickadee::Command.type.event?.must_equal(false) }
|
8
|
+
it { Chickadee::Command.type.match?(:command).must_equal(true) }
|
12
9
|
end
|
data/spec/requests/event_spec.rb
CHANGED
@@ -2,11 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require 'chickadee'
|
3
3
|
|
4
4
|
describe Chickadee::Event do
|
5
|
-
it {
|
6
|
-
it {
|
7
|
-
it {
|
8
|
-
|
9
|
-
def new_query
|
10
|
-
Chickadee::Event.new
|
11
|
-
end
|
5
|
+
it { Chickadee::Event.type.query?.must_equal(false) }
|
6
|
+
it { Chickadee::Event.type.command?.must_equal(false) }
|
7
|
+
it { Chickadee::Event.type.event?.must_equal(true) }
|
8
|
+
it { Chickadee::Event.type.match?(:event).must_equal(true) }
|
12
9
|
end
|
data/spec/requests/query_spec.rb
CHANGED
@@ -2,11 +2,8 @@ require 'spec_helper'
|
|
2
2
|
require 'chickadee'
|
3
3
|
|
4
4
|
describe Chickadee::Query do
|
5
|
-
it {
|
6
|
-
it {
|
7
|
-
it {
|
8
|
-
|
9
|
-
def new_query
|
10
|
-
Chickadee::Query.new
|
11
|
-
end
|
5
|
+
it { Chickadee::Query.type.query?.must_equal(true) }
|
6
|
+
it { Chickadee::Query.type.command?.must_equal(false) }
|
7
|
+
it { Chickadee::Query.type.event?.must_equal(false) }
|
8
|
+
it { Chickadee::Query.type.match?(:query).must_equal(true) }
|
12
9
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chickadee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Lott
|
@@ -94,8 +94,9 @@ files:
|
|
94
94
|
- lib/chickadee/requests/command.rb
|
95
95
|
- lib/chickadee/requests/event.rb
|
96
96
|
- lib/chickadee/requests/query.rb
|
97
|
-
- lib/chickadee/requests/
|
97
|
+
- lib/chickadee/requests/request_type.rb
|
98
98
|
- lib/chickadee/version.rb
|
99
|
+
- spec/dispatcher_spec.rb
|
99
100
|
- spec/dispatchers/command_dispatcher_spec.rb
|
100
101
|
- spec/dispatchers/event_dispatcher_spec.rb
|
101
102
|
- spec/dispatchers/handler_chain_struct_spec.rb
|
@@ -130,6 +131,7 @@ signing_key:
|
|
130
131
|
specification_version: 4
|
131
132
|
summary: Lightweight domain driven design library
|
132
133
|
test_files:
|
134
|
+
- spec/dispatcher_spec.rb
|
133
135
|
- spec/dispatchers/command_dispatcher_spec.rb
|
134
136
|
- spec/dispatchers/event_dispatcher_spec.rb
|
135
137
|
- spec/dispatchers/handler_chain_struct_spec.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Chickadee
|
2
|
-
class Request
|
3
|
-
def command?
|
4
|
-
request_type == :command
|
5
|
-
end
|
6
|
-
|
7
|
-
def query?
|
8
|
-
request_type == :query
|
9
|
-
end
|
10
|
-
|
11
|
-
def event?
|
12
|
-
request_type == :event
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def request_type
|
18
|
-
self.class.name.split('::').last.downcase.to_sym
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|