Project

reply

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
An standarized reply object
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.1
~> 1.0
~> 2.0
~> 3.12
~> 2.14
 Project Readme

Reply

A simple class used to encapsulate the reply from a service / interactor

Build Status

Usage

  reply = Reply.new

  # add message
  reply.add_message("Something")

  # add multiple messages
  reply.add_messages(["x", "y"])

  # mark the reply as succesful (this is the default)
  reply.success!

  # mark as warning
  reply.warning!

  # mark as error
  reply.error!

  # add error message and mark as error at the same time
  reply.add_error("Something bad happend")

  # add error messages and mark as error
  reply.add_error(["Error 1", "Error 2"])

  # reply.error! .success!, .warning! also accept an optional message
  reply.error!("I don't like you")

  # reply.error returns the reply itself, so you can do one liners like:
  return reply.error!("Didn't work")

  # check if reply was successful
  reply.successful?
  reply.success?

  # check if reply was unsuccessful
  reply.error?
  reply.failure?

  # add some data to the reply
  reply.data = something

  # add a status to the reply
  # this is independent of success, error and warning
  reply.status = 401

  # copy all the errors from an active record object
  reply.replace_messages_with_errors_for(active_record_object)

Testing

rake spec

or

guard start

Release

This gem uses jeweler https://github.com/technicalpickles/jeweler

rake version:bump:minor rake release

Copyright

Copyright © 2014 Sebastian Porto. See LICENSE.txt for further details.