Skip to content

Latest commit

 

History

History
50 lines (33 loc) · 1.51 KB

README.md

File metadata and controls

50 lines (33 loc) · 1.51 KB

DealWithIt

DealWithIt

Maintainability Test Coverage CircleCI

Installation

Add this line to your application's Gemfile:

gem 'deal_with_it'

And then execute:

$ bundle

Usage

Include the handler base on your ApplicationController or in any class you wish to handle.

class ApplicationController < ActionController::Base
  include DealWithIt
end

Create your custom handler anywhere in the app.

# app/handlers/record_not_found_handler.rb
class RecordNotFoundHandler < DealWithIt::Handler
  deal ActiveRecord::RecordNotFound, with: ->(error) do
    render json: { message: 'Oopsie, we didn\'t found that stuff' }, status: :not_found
  end
end

Note that render is a method that comes from the ActionController itself, it could be any method from the class that included the DealWithIt module.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/leonardofalk/deal_with_it.

License

The gem is available as open source under the terms of the MIT License.