serf 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -12
- data/lib/serf/middleware/error_handler.rb +7 -9
- data/lib/serf/parcel_factory.rb +45 -0
- data/lib/serf/serfer.rb +13 -18
- data/lib/serf/version.rb +1 -1
- data/serf.gemspec +1 -1
- data/spec/serf/middleware/error_handler_spec.rb +28 -0
- data/spec/serf/parcel_factory_spec.rb +99 -0
- data/spec/serf/serfer_spec.rb +48 -26
- data/spec/support/factories.rb +5 -0
- metadata +9 -9
- data/lib/serf/parcel_builder.rb +0 -27
- data/spec/serf/parcel_builder_spec.rb +0 -46
data/.gitignore
CHANGED
@@ -1,21 +1,10 @@
|
|
1
1
|
# Gemfile.lock because this is a library, not a deployable application.
|
2
2
|
Gemfile.lock
|
3
|
-
|
4
|
-
# rcov generated
|
5
3
|
coverage
|
6
|
-
|
7
|
-
# rdoc generated
|
8
4
|
rdoc
|
9
|
-
|
10
|
-
# yard generated
|
11
5
|
doc
|
12
6
|
.yardoc
|
13
|
-
|
14
|
-
# bundler config
|
15
7
|
.bundle
|
16
|
-
|
17
|
-
# bundler installs here if bundle path is set to "vendor"
|
18
8
|
vendor
|
19
|
-
|
20
|
-
# generated builds
|
21
9
|
pkg
|
10
|
+
tmp
|
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'hashie'
|
2
2
|
require 'optser'
|
3
3
|
|
4
|
-
require 'serf/
|
4
|
+
require 'serf/parcel_factory'
|
5
5
|
require 'serf/util/error_handling'
|
6
|
-
require 'serf/util/uuidable'
|
7
6
|
|
8
7
|
module Serf
|
9
8
|
module Middleware
|
@@ -16,8 +15,7 @@ module Middleware
|
|
16
15
|
include Serf::Util::ErrorHandling
|
17
16
|
|
18
17
|
attr_reader :app
|
19
|
-
attr_reader :
|
20
|
-
attr_reader :uuidable
|
18
|
+
attr_reader :parcel_factory
|
21
19
|
|
22
20
|
##
|
23
21
|
# @param app the app
|
@@ -27,8 +25,7 @@ module Middleware
|
|
27
25
|
@app = app
|
28
26
|
|
29
27
|
# Tunable knobs
|
30
|
-
@
|
31
|
-
@uuidable = opts.get(:uuidable) { Serf::Util::Uuidable.new }
|
28
|
+
@parcel_factory = opts.get(:parcel_factory) { Serf::ParcelFactory.new }
|
32
29
|
end
|
33
30
|
|
34
31
|
def call(parcel)
|
@@ -42,9 +39,10 @@ module Middleware
|
|
42
39
|
|
43
40
|
# We got an error message instead, so build out the headers
|
44
41
|
# and return the parcel.
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
return parcel_factory.create(
|
43
|
+
kind: 'serf/events/caught_error',
|
44
|
+
parent: parcel,
|
45
|
+
message: error_message)
|
48
46
|
end
|
49
47
|
|
50
48
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
require 'optser'
|
3
|
+
|
4
|
+
require 'serf/util/uuidable'
|
5
|
+
|
6
|
+
module Serf
|
7
|
+
|
8
|
+
##
|
9
|
+
# Creates Parcels as Hashie::Mash objects with headers and messages.
|
10
|
+
#
|
11
|
+
class ParcelFactory
|
12
|
+
attr_reader :mash_class
|
13
|
+
attr_reader :uuidable
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
opts = Optser.extract_options! args
|
17
|
+
|
18
|
+
@mash_class = opts.get :mash_class, Hashie::Mash
|
19
|
+
@uuidable = opts.get(:uuidable) { Serf::Util::Uuidable.new }
|
20
|
+
end
|
21
|
+
|
22
|
+
def create(*args)
|
23
|
+
opts = Optser.extract_options! args
|
24
|
+
|
25
|
+
# Get parameters
|
26
|
+
kind = opts.get :kind
|
27
|
+
parent = opts.get :parent, {}
|
28
|
+
headers = opts.get :headers, {}
|
29
|
+
message = opts.get :message, {}
|
30
|
+
|
31
|
+
# Coerce to mashes.
|
32
|
+
parent = mash_class.new(parent) unless parent.kind_of? mash_class
|
33
|
+
headers = mash_class.new(headers) unless headers.kind_of? mash_class
|
34
|
+
|
35
|
+
# Create a new headers object w/ uuids set from the parent and kind.
|
36
|
+
headers = headers.merge uuidable.create_uuids(parent.headers)
|
37
|
+
headers.kind = kind
|
38
|
+
|
39
|
+
# Return a final parcel, coerced as a mash.
|
40
|
+
mash_class.new headers: headers, message: message
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/lib/serf/serfer.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
require 'hashie'
|
2
1
|
require 'optser'
|
3
2
|
|
4
|
-
require 'serf/
|
5
|
-
require 'serf/util/uuidable'
|
3
|
+
require 'serf/parcel_factory'
|
6
4
|
|
7
5
|
module Serf
|
8
6
|
|
@@ -11,8 +9,7 @@ module Serf
|
|
11
9
|
#
|
12
10
|
class Serfer
|
13
11
|
attr_reader :interactor
|
14
|
-
attr_reader :
|
15
|
-
attr_reader :uuidable
|
12
|
+
attr_reader :parcel_factory
|
16
13
|
|
17
14
|
def initialize(interactor, *args)
|
18
15
|
opts = Optser.extract_options! args
|
@@ -21,26 +18,24 @@ module Serf
|
|
21
18
|
@interactor = interactor
|
22
19
|
|
23
20
|
# Tunable knobs
|
24
|
-
@
|
25
|
-
@uuidable = opts.get(:uuidable) { Serf::Util::Uuidable.new }
|
21
|
+
@parcel_factory = opts.get(:parcel_factory) { Serf::ParcelFactory.new }
|
26
22
|
end
|
27
23
|
|
28
24
|
##
|
29
25
|
# Rack-like call to run the Interactor's use-case.
|
30
26
|
#
|
31
27
|
def call(parcel)
|
32
|
-
headers = parcel[:headers]
|
33
|
-
message = parcel[:message]
|
34
|
-
|
35
28
|
# 1. Execute interactor
|
36
|
-
response_kind, response_message = interactor.call message
|
37
|
-
|
38
|
-
# 2.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
29
|
+
response_kind, response_message = interactor.call parcel[:message]
|
30
|
+
|
31
|
+
# 2. Return a new response parcel with:
|
32
|
+
# a. uuids set from parent parcel
|
33
|
+
# b. kind set to response kind
|
34
|
+
# c. the message set to response_message
|
35
|
+
return parcel_factory.create(
|
36
|
+
parent: parcel,
|
37
|
+
kind: response_kind,
|
38
|
+
message: response_message)
|
44
39
|
end
|
45
40
|
|
46
41
|
end
|
data/lib/serf/version.rb
CHANGED
data/serf.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
|
|
23
23
|
]
|
24
24
|
|
25
25
|
gem.add_runtime_dependency('hashie', ['>= 1.2.0'])
|
26
|
-
gem.add_runtime_dependency('ice_nine', ['>= 0.
|
26
|
+
gem.add_runtime_dependency('ice_nine', ['>= 0.6.0'])
|
27
27
|
gem.add_runtime_dependency('optser', ['>= 0.1.0'])
|
28
28
|
gem.add_runtime_dependency('uuidtools', ['>= 2.1.3'])
|
29
29
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
require 'factory_girl'
|
4
|
+
|
3
5
|
require 'serf/middleware/error_handler'
|
4
6
|
|
5
7
|
describe Serf::Middleware::ErrorHandler do
|
@@ -7,6 +9,13 @@ describe Serf::Middleware::ErrorHandler do
|
|
7
9
|
describe '#call' do
|
8
10
|
|
9
11
|
context 'has a raised error' do
|
12
|
+
let(:request_parcel) {
|
13
|
+
FactoryGirl.create :random_parcel
|
14
|
+
}
|
15
|
+
let(:response_parcel) {
|
16
|
+
FactoryGirl.create :random_parcel
|
17
|
+
}
|
18
|
+
|
10
19
|
subject {
|
11
20
|
described_class.new(proc { |parcel|
|
12
21
|
raise 'Some Runtime Error'
|
@@ -24,6 +33,25 @@ describe Serf::Middleware::ErrorHandler do
|
|
24
33
|
parcel = subject.call({})
|
25
34
|
expect(parcel[:headers][:kind]).to eq('serf/events/caught_error')
|
26
35
|
end
|
36
|
+
|
37
|
+
it 'uses parcel factory w/ kind, parent, and error message' do
|
38
|
+
mock_parcel_factory = double 'parcel_factory'
|
39
|
+
mock_parcel_factory.
|
40
|
+
should_receive(:create).
|
41
|
+
with({
|
42
|
+
parent: request_parcel,
|
43
|
+
kind: 'serf/events/caught_error',
|
44
|
+
message: anything()
|
45
|
+
}).
|
46
|
+
and_return(response_parcel)
|
47
|
+
|
48
|
+
app = described_class.new(proc { |parcel|
|
49
|
+
raise 'Some Runtime Error'
|
50
|
+
},
|
51
|
+
parcel_factory: mock_parcel_factory)
|
52
|
+
response = app.call request_parcel
|
53
|
+
expect(response).to eq(response_parcel)
|
54
|
+
end
|
27
55
|
end
|
28
56
|
|
29
57
|
context 'has a succeeding app' do
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'hashie'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
require 'serf/parcel_factory'
|
7
|
+
|
8
|
+
describe Serf::ParcelFactory do
|
9
|
+
|
10
|
+
describe '#build' do
|
11
|
+
let(:response_kind) {
|
12
|
+
SecureRandom.hex
|
13
|
+
}
|
14
|
+
let(:response_headers) {
|
15
|
+
FactoryGirl.create :random_headers
|
16
|
+
}
|
17
|
+
let(:response_message) {
|
18
|
+
FactoryGirl.create :random_message
|
19
|
+
}
|
20
|
+
let(:parent_parcel) {
|
21
|
+
FactoryGirl.create :random_parcel
|
22
|
+
}
|
23
|
+
|
24
|
+
it 'returns a Hashie Mash' do
|
25
|
+
parcel = subject.create
|
26
|
+
expect(parcel).to be_a_kind_of(Hashie::Mash)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns the headers as a Hashie Mash' do
|
30
|
+
parcel = subject.create
|
31
|
+
expect(parcel.headers).to be_a_kind_of(Hashie::Mash)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'sets nil kind in parcel headers' do
|
35
|
+
parcel = subject.create
|
36
|
+
expect(parcel.headers.kind).to be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'sets nil kind in parcel headers to overwrite headers kind' do
|
40
|
+
parcel = subject.create headers: response_headers
|
41
|
+
expect(response_headers.kind).to_not be_nil
|
42
|
+
expect(parcel.headers.kind).to be_nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'sets a kind in parcel headers to overwrite headers' do
|
46
|
+
parcel = subject.create kind: response_kind, headers: response_headers
|
47
|
+
expect(response_headers.kind).to_not eq(response_kind)
|
48
|
+
expect(parcel.headers.kind).to eq(response_kind)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'sets uuid, w/ nil origin and parent in parcel headers' do
|
52
|
+
parcel = subject.create
|
53
|
+
expect(parcel.headers.uuid).to_not be_nil
|
54
|
+
expect(parcel.headers.parent_uuid).to be_nil
|
55
|
+
expect(parcel.headers.origin_uuid).to be_nil
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'sets uuid, origin and parent in response headers from parent' do
|
59
|
+
parcel = subject.create parent: parent_parcel
|
60
|
+
expect(parcel.headers.uuid).to_not be_nil
|
61
|
+
expect(parcel.headers.parent_uuid).to eq(parent_parcel.headers.uuid)
|
62
|
+
expect(parcel.headers.origin_uuid).
|
63
|
+
to eq(parent_parcel.headers.origin_uuid)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns the message as a Hashie Mash' do
|
67
|
+
parcel = subject.create
|
68
|
+
expect(parcel.message).to be_a_kind_of(Hashie::Mash)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'sets empty parcel message as default' do
|
72
|
+
parcel = subject.create
|
73
|
+
expect(parcel[:message]).to eq({})
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'sets the message, given a message' do
|
77
|
+
parcel = subject.create message: response_message
|
78
|
+
expect(parcel.message).to eq(response_message)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'sets meets expectations given kind, headers, message and parent' do
|
82
|
+
parcel = subject.create(
|
83
|
+
parent: parent_parcel,
|
84
|
+
kind: response_kind,
|
85
|
+
headers: response_headers,
|
86
|
+
message: response_message)
|
87
|
+
expect(response_headers.kind).to_not eq(response_kind)
|
88
|
+
expect(parcel.headers.kind).to eq(response_kind)
|
89
|
+
expect(parcel.headers.uuid).to_not be_nil
|
90
|
+
expect(parcel.headers.parent_uuid).to eq(parent_parcel.headers.uuid)
|
91
|
+
expect(parcel.headers.origin_uuid).
|
92
|
+
to eq(parent_parcel.headers.origin_uuid)
|
93
|
+
expect(parcel.headers.option_a).to eq(response_headers.option_a)
|
94
|
+
expect(parcel.message).to eq(response_message)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
data/spec/serf/serfer_spec.rb
CHANGED
@@ -1,59 +1,81 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
require 'hashie'
|
4
|
+
require 'securerandom'
|
5
|
+
|
3
6
|
require 'serf/serfer'
|
4
7
|
|
5
8
|
describe Serf::Serfer do
|
6
9
|
|
7
10
|
describe '#call' do
|
11
|
+
let(:request_parcel) {
|
12
|
+
Hashie::Mash.new(
|
13
|
+
headers: request_headers,
|
14
|
+
message: request_message)
|
15
|
+
}
|
16
|
+
let(:request_headers) {
|
17
|
+
FactoryGirl.create :random_headers
|
18
|
+
}
|
8
19
|
let(:request_message) {
|
9
20
|
FactoryGirl.create :random_message
|
10
21
|
}
|
22
|
+
let(:response_kind) {
|
23
|
+
SecureRandom.hex
|
24
|
+
}
|
11
25
|
let(:response_message) {
|
12
26
|
FactoryGirl.create :random_message
|
13
27
|
}
|
28
|
+
let(:disconnected_response_parcel) {
|
29
|
+
FactoryGirl.create :random_parcel
|
30
|
+
}
|
14
31
|
|
15
32
|
it 'calls app with message' do
|
16
33
|
mock_app = double 'mock_app'
|
17
34
|
mock_app.should_receive(:call).with(request_message)
|
18
35
|
serfer = described_class.new mock_app
|
19
|
-
serfer.call
|
20
|
-
headers: nil,
|
21
|
-
message: request_message)
|
36
|
+
serfer.call request_parcel
|
22
37
|
end
|
23
38
|
|
24
|
-
it 'returns a parcel' do
|
39
|
+
it 'returns a parcel with a kind, message and uuids' do
|
25
40
|
mock_app = double 'mock_app'
|
26
41
|
mock_app.
|
27
42
|
should_receive(:call).
|
28
43
|
with(request_message).
|
29
|
-
and_return([
|
44
|
+
and_return([response_kind, response_message])
|
30
45
|
serfer = described_class.new mock_app
|
31
|
-
|
32
|
-
|
33
|
-
|
46
|
+
|
47
|
+
parcel = serfer.call request_parcel
|
48
|
+
|
49
|
+
# We expect the kind and message to match.
|
50
|
+
# We also expect that the uuid is some value
|
51
|
+
# We also expect that the response parent uuid matches request uuid
|
52
|
+
# We also expect that the response origin uuid matches request origin's.
|
53
|
+
expect(parcel.headers.kind).to eq(response_kind)
|
54
|
+
expect(parcel.headers.uuid).to_not be_nil
|
55
|
+
expect(parcel.headers.origin_uuid).
|
56
|
+
to eq(request_parcel.headers.origin_uuid)
|
57
|
+
expect(parcel.headers.parent_uuid).
|
58
|
+
to eq(request_parcel.headers.uuid)
|
34
59
|
expect(parcel.message).to eq(response_message)
|
35
60
|
end
|
36
61
|
|
37
|
-
it '
|
38
|
-
|
39
|
-
|
40
|
-
should_receive(:
|
41
|
-
with(
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
expect(parcel.headers.kind).to eq('KIND')
|
48
|
-
end
|
62
|
+
it 'uses parcel factory w/ message and headers' do
|
63
|
+
mock_parcel_factory = double 'parcel_factory'
|
64
|
+
mock_parcel_factory.
|
65
|
+
should_receive(:create).
|
66
|
+
with({
|
67
|
+
parent: request_parcel,
|
68
|
+
kind: response_kind,
|
69
|
+
message: response_message
|
70
|
+
}).
|
71
|
+
and_return(disconnected_response_parcel)
|
49
72
|
|
50
|
-
it 'generate uuids' do
|
51
|
-
uuidable = double 'uuidable'
|
52
|
-
uuidable.should_receive(:create_uuids).and_return({})
|
53
73
|
serfer = described_class.new(
|
54
|
-
lambda {|obj| return
|
55
|
-
|
56
|
-
serfer.call
|
74
|
+
lambda {|obj| return response_kind, response_message },
|
75
|
+
parcel_factory: mock_parcel_factory)
|
76
|
+
parcel = serfer.call request_parcel
|
77
|
+
|
78
|
+
expect(parcel).to eq(disconnected_response_parcel)
|
57
79
|
end
|
58
80
|
|
59
81
|
end
|
data/spec/support/factories.rb
CHANGED
@@ -15,6 +15,8 @@ FactoryGirl.define do
|
|
15
15
|
factory :random_parcel, class: Hashie::Mash do
|
16
16
|
headers {{
|
17
17
|
uuid: generate(:random_string),
|
18
|
+
origin_uuid: generate(:random_string),
|
19
|
+
parent_uuid: generate(:random_string),
|
18
20
|
kind: generate(:random_string)
|
19
21
|
}}
|
20
22
|
message {{
|
@@ -24,7 +26,10 @@ FactoryGirl.define do
|
|
24
26
|
|
25
27
|
factory :random_headers, class: Hashie::Mash do
|
26
28
|
uuid { generate(:random_string) }
|
29
|
+
origin_uuid { generate(:random_string) }
|
30
|
+
parent_uuid { generate(:random_string) }
|
27
31
|
kind { generate(:random_string) }
|
32
|
+
option_a { generate(:random_string) }
|
28
33
|
end
|
29
34
|
|
30
35
|
factory :random_message, class: Hashie::Mash do
|
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.
|
4
|
+
version: 0.12.1
|
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-
|
12
|
+
date: 2012-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 0.
|
37
|
+
version: 0.6.0
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 0.
|
45
|
+
version: 0.6.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: optser
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,7 +106,7 @@ files:
|
|
106
106
|
- lib/serf/middleware/policy_checker.rb
|
107
107
|
- lib/serf/middleware/request_timer.rb
|
108
108
|
- lib/serf/middleware/uuid_tagger.rb
|
109
|
-
- lib/serf/
|
109
|
+
- lib/serf/parcel_factory.rb
|
110
110
|
- lib/serf/serfer.rb
|
111
111
|
- lib/serf/util/error_handling.rb
|
112
112
|
- lib/serf/util/null_object.rb
|
@@ -126,7 +126,7 @@ files:
|
|
126
126
|
- spec/serf/middleware/policy_checker_spec.rb
|
127
127
|
- spec/serf/middleware/request_timer_spec.rb
|
128
128
|
- spec/serf/middleware/uuid_tagger_spec.rb
|
129
|
-
- spec/serf/
|
129
|
+
- spec/serf/parcel_factory_spec.rb
|
130
130
|
- spec/serf/serfer_spec.rb
|
131
131
|
- spec/serf/util/error_handling_spec.rb
|
132
132
|
- spec/serf/util/null_object_spec.rb
|
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
segments:
|
157
157
|
- 0
|
158
|
-
hash:
|
158
|
+
hash: 4471778564530978528
|
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:
|
167
|
+
hash: 4471778564530978528
|
168
168
|
requirements: []
|
169
169
|
rubyforge_project:
|
170
170
|
rubygems_version: 1.8.23
|
@@ -183,7 +183,7 @@ test_files:
|
|
183
183
|
- spec/serf/middleware/policy_checker_spec.rb
|
184
184
|
- spec/serf/middleware/request_timer_spec.rb
|
185
185
|
- spec/serf/middleware/uuid_tagger_spec.rb
|
186
|
-
- spec/serf/
|
186
|
+
- spec/serf/parcel_factory_spec.rb
|
187
187
|
- spec/serf/serfer_spec.rb
|
188
188
|
- spec/serf/util/error_handling_spec.rb
|
189
189
|
- spec/serf/util/null_object_spec.rb
|
data/lib/serf/parcel_builder.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'hashie'
|
2
|
-
require 'optser'
|
3
|
-
|
4
|
-
module Serf
|
5
|
-
|
6
|
-
##
|
7
|
-
# Builds Parcels as Hashie::Mash objects with headers and messages.
|
8
|
-
#
|
9
|
-
class ParcelBuilder
|
10
|
-
attr_reader :mash_class
|
11
|
-
|
12
|
-
def initialize(*args)
|
13
|
-
opts = Optser.extract_options! args
|
14
|
-
|
15
|
-
@mash_class = opts.get :mash_class, Hashie::Mash
|
16
|
-
end
|
17
|
-
|
18
|
-
def build(headers=nil, message=nil)
|
19
|
-
# We want to make sure that our headers and message are Mashes.
|
20
|
-
headers = mash_class.new(headers) unless headers.kind_of? mash_class
|
21
|
-
message = mash_class.new(message) unless message.kind_of? mash_class
|
22
|
-
mash_class.new headers: headers, message: message
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'hashie'
|
4
|
-
|
5
|
-
require 'serf/parcel_builder'
|
6
|
-
|
7
|
-
describe Serf::ParcelBuilder do
|
8
|
-
|
9
|
-
describe '#build' do
|
10
|
-
let(:random_headers) {
|
11
|
-
FactoryGirl.create :random_headers
|
12
|
-
}
|
13
|
-
let(:random_message) {
|
14
|
-
FactoryGirl.create :random_message
|
15
|
-
}
|
16
|
-
|
17
|
-
it 'returns a Hashie' do
|
18
|
-
parcel = subject.build
|
19
|
-
expect(parcel).to be_a_kind_of(Hashie::Mash)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'sets default parcel headers' do
|
23
|
-
parcel = subject.build
|
24
|
-
expect(parcel[:headers]).to eq({})
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'sets default parcel message' do
|
28
|
-
parcel = subject.build
|
29
|
-
expect(parcel[:headers]).to eq({})
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'sets given headers and message' do
|
33
|
-
parcel = subject.build random_headers, random_message
|
34
|
-
expect(parcel[:headers]).to eq(random_headers)
|
35
|
-
expect(parcel[:message]).to eq(random_message)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'will coerce headers and message into Hashie::Mash' do
|
39
|
-
parcel = subject.build nil, nil
|
40
|
-
expect(parcel[:headers]).to be_a_kind_of(Hashie::Mash)
|
41
|
-
expect(parcel[:message]).to be_a_kind_of(Hashie::Mash)
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|