Outcome

This Ruby gem provides a standardized container for the outcome of a process.

It comes with detailed documentation.

Installation

Add this line to your application's Gemfile:

gem 'outcome'

And then execute:

$ bundle

Or install it yourself as:

$ gem install outcome

Usage

Whenever you need to return more than a simple object as the outcome of a process, you can use an instance of the Outcome class.

An outcome has the following attributes:

  • success: Indicates if the process was successful (Bool)
  • result: The return value of the process. Anything you want to return. (Object)
  • messages: Any messages generated during the process. (Array of strings, optional)
  • errors: Any errors generated during the process. (Array of strings, optional)
  • warnings: Any warnings generated during the process. (Array of strings, optional)

Here is how you use it in your code:

def my_process
  # process code ...
  if successful
    Outcome.new(true, [1,2,3], ['All went well'])
  else
    Outcome.new(false, nil, [], ['All went wrong while doing ...'])
  end
end

This gives you a standardized process outcome interface. No rocket science, just one less thing to re-invent.

License

MIT (see LICENSE file).

Contributing

  1. Fork it ( http://github.com//outcome/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request