Sha256: 365854caf74f4556df1833c25f15814beec605b95cae6cd29a353dd362ba1fe7

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

module Substation

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

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

    # 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

1 entries across 1 versions & 1 rubygems

Version Path
substation-0.0.3 lib/substation/request.rb