class Substation::Request
Encapsulates the application environment and an input model instance
Public Instance Methods
error(output)
click to toggle source
Create a new failure response
@example
class SomeUseCase def self.call(request) error = perform_use_case request.error(error) end end
@param [Object] output
the data associated with the response
@return [Response::Failure]
@api public
# File lib/substation/request.rb, line 65 def error(output) respond_with(Response::Failure, output) end
success(output)
click to toggle source
Create a new successful response
@example
class SomeUseCase def self.call(request) data = perform_use_case request.success(data) end end
@param [Object] output
the data associated with the response
@return [Response::Success]
@api public
# File lib/substation/request.rb, line 44 def success(output) respond_with(Response::Success, output) end
to_request(new_input = Undefined)
click to toggle source
Return self or a new instance with input
@param [Object] input
the input for the new instance
@return [self]
if +input+ is {Undefined}
@return [Request]
a new instance with +input+
@api private
# File lib/substation/request.rb, line 81 def to_request(new_input = Undefined) new_input.equal?(Undefined) ? self : self.class.new(name, env, new_input) end
Private Instance Methods
respond_with(klass, output)
click to toggle source
Instantiate an instance of klass
and pass output
@param [Response::Success, Response::Failure] klass
the response class
@param [Object] output
the data associated with the response
@return [Response::Success, Response::Failure]
@api private
# File lib/substation/request.rb, line 98 def respond_with(klass, output) klass.new(self, output) end