Class: Substation::Request

Inherits:
Object
  • Object
show all
Includes:
Adamantium::Flat
Defined in:
lib/substation/request.rb

Overview

Encapsulates the application environment and an input model instance

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envObject (readonly)

Returns the application environment

Returns:

  • (Object)

    the application environment


# File 'lib/substation/request.rb', line 14

#inputObject (readonly) Also known as: data

Returns the input data

Returns:

  • (Object)

    the input data


# File 'lib/substation/request.rb', line 17

#nameSymbol (readonly)

Returns the name of the request

Returns:

  • (Symbol)

    the name of the request


# File 'lib/substation/request.rb', line 11

Instance Method Details

#error(output) ⇒ Response::Failure

Create a new failure response

Examples:


class SomeUseCase
  def self.call(request)
    error = perform_use_case
    request.error(error)
  end
end

Parameters:

  • output (Object)

    the data associated with the response

Returns:


65
66
67
# File 'lib/substation/request.rb', line 65

def error(output)
  respond_with(Response::Failure, output)
end

#success(output) ⇒ Response::Success

Create a new successful response

Examples:


class SomeUseCase
  def self.call(request)
    data = perform_use_case
    request.success(data)
  end
end

Parameters:

  • output (Object)

    the data associated with the response

Returns:


44
45
46
# File 'lib/substation/request.rb', line 44

def success(output)
  respond_with(Response::Success, output)
end

#to_request(new_input = Undefined) ⇒ self, 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 self or a new instance with input

Parameters:

  • input (Object)

    the input for the new instance

Returns:


81
82
83
# 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