Class: Substation::Response Abstract
- Inherits:
-
Object
- Object
- Substation::Response
- Includes:
- AbstractType, Adamantium::Flat
- Defined in:
- lib/substation/response.rb,
lib/substation/response/api.rb,
lib/substation/response/failure.rb,
lib/substation/response/success.rb,
lib/substation/response/exception.rb,
lib/substation/response/exception/output.rb
Overview
Base class for action responses
The following code illustrates context and serves as setup for all instance method doc examples
module App
class Environment
def initialize(storage, logger)
@storage, @logger = storage, logger
end
end
class SuccessfulAction
def self.call(request)
data = perform_work
request.success(data)
end
end
class FailingAction
def self.call(request)
error = perform_work
request.error(error)
end
end
end
storage = SomeStorageAbstraction.new
env = App::Environment.new(storage, Logger.new($stdout))
dispatcher = Substation::Dispatcher.coerce({
:successful_action => { :action => App::SuccessfulAction },
:failing_action => { :action => App::FailingAction }
}, env)
Defined Under Namespace
Modules: API Classes: Exception, Failure, Success
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
The application environment used within an action.
-
#input ⇒ Object
readonly
The request model instance passed into an action.
Instance Method Summary collapse
-
#exception? ⇒ true
private
Test wether processing raised an exception.
-
#initialize(_request, _output) ⇒ undefined
constructor
private
Initialize a new instance.
-
#success? ⇒ Boolean
abstract
Indicates wether this is a successful response or not.
-
#to_request(new_input = output) ⇒ Request
private
Return a Request instance built upon this response.
Constructor Details
#initialize(_request, _output) ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a new instance
85 86 87 88 89 |
# File 'lib/substation/response.rb', line 85 def initialize(_request, _output) super @env = request.env @input = request.input end |
Instance Attribute Details
#env ⇒ Object (readonly)
The application environment used within an action
58 59 60 |
# File 'lib/substation/response.rb', line 58 def env @env end |
#input ⇒ Object (readonly)
The request model instance passed into an action
72 73 74 |
# File 'lib/substation/response.rb', line 72 def input @input end |
Instance Method Details
#exception? ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Test wether processing raised an exception
114 115 116 |
# File 'lib/substation/response.rb', line 114 def exception? false end |
#success? ⇒ Boolean
Indicates wether this is a successful response or not
107 |
# File 'lib/substation/response.rb', line 107 abstract_method :success? |
#to_request(new_input = output) ⇒ Request
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a Substation::Request instance built upon this response
123 124 125 |
# File 'lib/substation/response.rb', line 123 def to_request(new_input = output) Request.new(request.name, env, new_input) end |