-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an outgoing Processor::Transformer
Respective handlers may transform the response data into any other object. This will be useful for handlers that perform serialization, rendering, generating a rack response etc ...
- Loading branch information
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Substation | ||
module Processor | ||
|
||
# A processor that transforms output data into something else | ||
class Transformer | ||
|
||
include Processor::Outgoing | ||
|
||
# Transform response data into something else | ||
# | ||
# @param [Response] response | ||
# the response to process | ||
# | ||
# @return [Response] | ||
# | ||
# @api private | ||
def call(response) | ||
respond_with(response, handler.call(response)) | ||
end | ||
|
||
end # class Wrapper | ||
end # module Processor | ||
end # module Substation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# encoding: utf-8 | ||
|
||
require 'spec_helper' | ||
|
||
describe Processor::Transformer, '#call' do | ||
subject { object.call(response) } | ||
|
||
let(:object) { described_class.new(s_env, Spec::Transformer) } | ||
let(:s_env) { mock } | ||
let(:response) { Response::Success.new(request, output) } | ||
let(:request) { Request.new(name, env, input) } | ||
let(:name) { mock } | ||
let(:env) { mock } | ||
let(:input) { mock } | ||
let(:output) { mock } | ||
|
||
let(:transformed) { Response::Success.new(request, data) } | ||
let(:data) { Spec::Transformer.call(response) } | ||
|
||
it { should eql(transformed) } | ||
end |