Class: Substation::Response Abstract
- Inherits:
-
Object
- Object
- Substation::Response
- Includes:
- AbstractType, Adamantium::Flat
- Defined in:
- lib/substation/response.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
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.
-
#output ⇒ Object
readonly
The data wrapped inside an action Response.
-
#request ⇒ Request
readonly
The request that lead to this response.
Instance Method Summary collapse
-
#initialize(request, output) ⇒ undefined
constructor
private
Initialize a new instance.
-
#success? ⇒ Boolean
abstract
Indicates wether this is a successful response or not.
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
105 106 107 108 109 110 |
# File 'lib/substation/response.rb', line 105 def initialize(request, output) @request = request @env = @request.env @input = @request.input @output = output end |
Instance Attribute Details
#env ⇒ Object (readonly)
The application environment used within an action
66 67 68 |
# File 'lib/substation/response.rb', line 66 def env @env end |
#input ⇒ Object (readonly)
The request model instance passed into an action
80 81 82 |
# File 'lib/substation/response.rb', line 80 def input @input end |
#output ⇒ Object (readonly)
The data wrapped inside an action Substation::Response
92 93 94 |
# File 'lib/substation/response.rb', line 92 def output @output end |
#request ⇒ Request (readonly)
The request that lead to this response
54 55 56 |
# File 'lib/substation/response.rb', line 54 def request @request end |
Instance Method Details
#success? ⇒ Boolean
Indicates wether this is a successful response or not
128 |
# File 'lib/substation/response.rb', line 128 abstract_method :success? |