serf 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -23,20 +23,24 @@ Serf Links
23
23
  Interactors
24
24
  -----------
25
25
 
26
- The piece of work to be done. This takes in a request, represented
27
- by a "Message", and returns an "Event" as its result. The Interactor
28
- is the "Domain Controller" with respect to performing
26
+ The piece of work to be done. This takes in a request, represented by the
27
+ "Message" within the given "Parcel", and returns an "Event" as its result.
28
+ The Interactor is the "Domain Controller" with respect to performing
29
29
  Domain Layer business logic in coordinating and interacting with
30
30
  the Domain Layer's Entities (Value Objects and Entity Gateways).
31
31
 
32
32
  1. Include the "Serf::Interactor" module in your class.
33
- 2. Implement the 'call(message)' method.
33
+ 2. Implement the 'call(parcel)' method.
34
34
  3. Return the tuple: (kind, message)
35
35
  a. The kind is the string representation of the message type,
36
36
  This field is RECOMMENDED.
37
37
  b. The message field provides detailed return data about the
38
38
  interactor's processing.
39
39
  Hashie::Mash is suggested for the message, nil is acceptable.
40
+ c. By default, returning nil for both kind and message will still
41
+ result in a response parcel signifying that some Interactor received
42
+ the inbound parcel. But that is just a almost worthless piece of
43
+ information for the observer.
40
44
 
41
45
  The reason that the interactor SHOULD return a kind is to properly
42
46
  identify the semantic meaning of the returned message, even if
@@ -55,11 +59,11 @@ Example:
55
59
  @model = opts :model, MyModel
56
60
  end
57
61
 
58
- def call(message)
62
+ def call(parcel)
59
63
  # Do something w/ the message and opts.
60
64
  # Simple data structures for the Interactor's "Request".
61
65
 
62
- item = @model.find message.model_id
66
+ item = @model.find parcel.message.model_id
63
67
 
64
68
  # Make a simple data structure as the Interactor "Response".
65
69
  response = Hashie::Mash.new
@@ -82,7 +86,7 @@ code, etc.
82
86
 
83
87
  The Parcel in Ruby (Datastructure) is represented simply as:
84
88
 
85
- * A 2 element Hash: { headers: headers, message: message}.
89
+ * A 2 element Hash: { headers: headers, message: message }.
86
90
 
87
91
  NOTE: Hashie::Mash is *Awesome*. (https://github.com/intridea/hashie)
88
92
  NOTE: Serf passes the parcel as frozen Hashie::Mash instances
@@ -123,6 +127,12 @@ that hosts the Interactors. The Interactors themselves do not
123
127
  return any headers in the response. The Interactors are tasked to provide
124
128
  only business relevant data in the Event messages they return.
125
129
 
130
+ However, the full request parcel is given to the Interactors so the
131
+ request's header information can be used to annotate subsequent
132
+ chained requests to other Interactors. For example, the UUIDs in headers in
133
+ "Request A" given to "Interactor A" can be used to generate new tracking
134
+ UUID headers for "Request B" that is sent to "Interactor B". This allows
135
+ us to track the origin point of any piece of processing request and event..
126
136
 
127
137
  Policies
128
138
  --------
@@ -247,8 +257,8 @@ Serf Builder Example
247
257
  # my_lib/my_interactor.rb
248
258
  class MyInteractor
249
259
 
250
- def call(message)
251
- raise 'Error' if message.raise_an_error
260
+ def call(parcel)
261
+ raise 'Error' if parcel.message.raise_an_error
252
262
 
253
263
  # And return a message as result. Nil is valid response.
254
264
  return 'my_lib/events/success_event', { success: true }
data/lib/serf/serfer.rb CHANGED
@@ -26,7 +26,7 @@ module Serf
26
26
  #
27
27
  def call(parcel)
28
28
  # 1. Execute interactor
29
- response_kind, response_message = interactor.call parcel[:message]
29
+ response_kind, response_message = interactor.call parcel
30
30
 
31
31
  # 2. Return a new response parcel with:
32
32
  # a. uuids set from parent parcel
data/lib/serf/version.rb CHANGED
@@ -2,8 +2,8 @@ module Serf
2
2
 
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 12
6
- PATCH = 1
5
+ MINOR = 13
6
+ PATCH = 0
7
7
  BUILD = nil
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join '.'
9
9
  end
@@ -32,7 +32,7 @@ describe Serf::Builder do
32
32
 
33
33
  it 'runs the app' do
34
34
  response = subject.to_app.call request_parcel
35
- expect(response.message).to eq(request_parcel.message)
35
+ expect(response.message).to eq(request_parcel)
36
36
  expect(response.headers.kind).to eq(response_kind)
37
37
  end
38
38
 
@@ -29,9 +29,9 @@ describe Serf::Serfer do
29
29
  FactoryGirl.create :random_parcel
30
30
  }
31
31
 
32
- it 'calls app with message' do
32
+ it 'calls app with the parcel' do
33
33
  mock_app = double 'mock_app'
34
- mock_app.should_receive(:call).with(request_message)
34
+ mock_app.should_receive(:call).with(request_parcel)
35
35
  serfer = described_class.new mock_app
36
36
  serfer.call request_parcel
37
37
  end
@@ -40,7 +40,7 @@ describe Serf::Serfer do
40
40
  mock_app = double 'mock_app'
41
41
  mock_app.
42
42
  should_receive(:call).
43
- with(request_message).
43
+ with(request_parcel).
44
44
  and_return([response_kind, response_message])
45
45
  serfer = described_class.new mock_app
46
46
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.13.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-23 00:00:00.000000000 Z
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  segments:
157
157
  - 0
158
- hash: 4471778564530978528
158
+ hash: 1409923119992406308
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: 4471778564530978528
167
+ hash: 1409923119992406308
168
168
  requirements: []
169
169
  rubyforge_project:
170
170
  rubygems_version: 1.8.23