Sha256: a52ae2d9fca57f707031839f350f48f25c7ec9b6c827e7cd8d93a724d2d2da48

Contents?: true

Size: 1.96 KB

Versions: 5

Compression:

Stored size: 1.96 KB

Contents

module Substation

  # Encapsulates the application environment and an input model instance
  class Request

    include Concord.new(:env, :input)
    include Adamantium::Flat

    # The application environment
    #
    # @example
    #
    #   class SomeUseCase
    #     def self.call(request)
    #       request.env
    #     end
    #   end
    #
    # @return [Object]
    #
    # @api public
    attr_reader :env

    # The input passed to an action
    #
    # @example
    #
    #   class SomeUseCase
    #     def self.call(request)
    #       request.input
    #     end
    #   end
    #
    # @return [Object]
    #
    # @api public
    attr_reader :input

    # 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
    def success(output)
      respond_with(Response::Success, output)
    end

    # 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
    def error(output)
      respond_with(Response::Failure, output)
    end

    private

    # 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
    def respond_with(klass, output)
      klass.new(self, output)
    end

  end # class Request
end # module Substation

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
substation-0.0.8 lib/substation/request.rb
substation-0.0.7 lib/substation/request.rb
substation-0.0.6 lib/substation/request.rb
substation-0.0.5 lib/substation/request.rb
substation-0.0.4 lib/substation/request.rb