<commit_before># Rapporteur (rap-or-TUHR)

[![Gem Version](http://img.shields.io/gem/v/rapporteur.svg?style=flat)](http://rubygems.org/gems/rapporteur)
[![Build Status](http://img.shields.io/travis/envylabs/rapporteur/master.svg?style=flat)](https://travis-ci.org/envylabs/rapporteur)
[![Code Climate](http://img.shields.io/codeclimate/github/envylabs/rapporteur.svg?style=flat)](https://codeclimate.com/github/envylabs/rapporteur)
[![Dependency Status](https://gemnasium.com/envylabs/rapporteur.svg)](https://gemnasium.com/envylabs/rapporteur)
[![Inline docs](http://inch-ci.org/github/envylabs/rapporteur.svg?branch=master)](http://inch-ci.org/github/envylabs/rapporteur)


This gem provides a singular, status-checking endpoint to your application. The
endpoint provides a JSON response with either an HTTP 200 or an HTTP 500
response, depending on the current application environment.

When the environment tests successfully, an HTTP 200 response is returned with
the current application Git revision and server time:

```json
{
  "revision": "906731e6467ea381ba5bc70f103b85ed4178fee7",
  "time": "2013-05-19T05:38:46Z"
}
```

When an application validation fails, an HTTP 500 response is returned with a
collection of error messages, similar to the Rails < 4.2 responders for model
validations:

```json
{
  "errors": {
    "database": ["The application database is inaccessible or unavailable"]
  }
}
```

## Installation

To install, add this line to your application's Gemfile:

```ruby
gem 'rapporteur'
```

And then execute:

```bash
$ bundle install
```

### Supported environments

Supported Ruby versions:

* MRI 2.4
* MRI 2.3
* MRI 2.2
* MRI 2.1

Supported Rails versions:

* Rails 5.x.
* Rails 4.x.
* Rails 3.2.x.

Non-Rails environments are also supported (such as Sinatra), see Usage below
for details.

## Usage

By default, there are no application checks that run and the status endpoint
simply reports the current application revision and time. This is useful for a
basic connectivity check to be watched by a third party service like Pingdom
for a very simple, non-critical application.

You may optionally use any of the pre-defined checks (such as the ActiveRecord
connection check) to expand the robustness of the status checks. Adding a check
will execute that check each time the status endpoint is requested, so be
somewhat wary of doing _too_ much. See more in the [Adding checks
section](#adding-checks), below.

Further, you can define your own checks which could be custom to your
application or environment and report their own, unique errors.  The only
requirement is that the check objects are callable (respond to `#call`, like a
Proc). See more in the [Creating custom checks
section](#creating-custom-checks), below.

### The endpoint

This gem provides a new, single endpoint in your application. Specifically, it
creates a named `/status.json` route, with the "status" name. It does not match
on any other format or variation, which isolates the pollution of your
application routes.

If you'd like to link to the status endpoint from within your application (why,
I couldn't guess), you can use a standard Rails URL helper:

```ruby
link_to status_path
```

Were you already using the `/status.json` endpoint or the "status" route name?
Hmm. Well... you just broke it.

### Usage without Rails (i.e. Sinatra)

If your application does not have Rails loaded, the Rails Engine logic will be
bypassed. In this case, you must configure and run your Rapporteur reports
manually because, in the very least, your status route will not be
automatically generated as previously described.

So, here is an example usage in Sinatra:

```ruby
require "rapporteur"
require "sinatra/base"

class MyApp < Sinatra::Base
  get "/status.json" do
    content_type :json
    body Rapporteur.run.as_json.to_json
  end
end
```

Require `rapporteur` and then, at some point, call `Rapporteur.run` to execute<commit_msg>Add instructions for mounting the Rails endpoints.<commit_after># Rapporteur (rap-or-TUHR)

[![Gem Version](http://img.shields.io/gem/v/rapporteur.svg?style=flat)](http://rubygems.org/gems/rapporteur)
[![Build Status](http://img.shields.io/travis/envylabs/rapporteur/master.svg?style=flat)](https://travis-ci.org/envylabs/rapporteur)
[![Code Climate](http://img.shields.io/codeclimate/github/envylabs/rapporteur.svg?style=flat)](https://codeclimate.com/github/envylabs/rapporteur)
[![Dependency Status](https://gemnasium.com/envylabs/rapporteur.svg)](https://gemnasium.com/envylabs/rapporteur)
[![Inline docs](http://inch-ci.org/github/envylabs/rapporteur.svg?branch=master)](http://inch-ci.org/github/envylabs/rapporteur)


This gem provides a singular, status-checking endpoint to your application. The
endpoint provides a JSON response with either an HTTP 200 or an HTTP 500
response, depending on the current application environment.

When the environment tests successfully, an HTTP 200 response is returned with
the current application Git revision and server time:

```json
{
  "revision": "906731e6467ea381ba5bc70f103b85ed4178fee7",
  "time": "2013-05-19T05:38:46Z"
}
```

When an application validation fails, an HTTP 500 response is returned with a
collection of error messages, similar to the Rails < 4.2 responders for model
validations:

```json
{
  "errors": {
    "database": ["The application database is inaccessible or unavailable"]
  }
}
```

## Installation

To install, add this line to your application's Gemfile:

```ruby
gem 'rapporteur'
```

And then execute:

```bash
$ bundle install
```

### Supported environments

Supported Ruby versions:

* MRI 2.4
* MRI 2.3
* MRI 2.2
* MRI 2.1

Supported Rails versions:

* Rails 5.x.
* Rails 4.x.
* Rails 3.2.x.

Non-Rails environments are also supported (such as Sinatra), see Usage below
for details.

## Usage

By default, there are no application checks that run and the status endpoint
simply reports the current application revision and time. This is useful for a
basic connectivity check to be watched by a third party service like Pingdom
for a very simple, non-critical application.

You may optionally use any of the pre-defined checks (such as the ActiveRecord
connection check) to expand the robustness of the status checks. Adding a check
will execute that check each time the status endpoint is requested, so be
somewhat wary of doing _too_ much. See more in the [Adding checks
section](#adding-checks), below.

Further, you can define your own checks which could be custom to your
application or environment and report their own, unique errors.  The only
requirement is that the check objects are callable (respond to `#call`, like a
Proc). See more in the [Creating custom checks
section](#creating-custom-checks), below.

### Usage in a Rails application

If you're running in a Rails environment, then the included Rails Engine should
automatically get required and loaded. However, you will need to instruct your
application where to mount the status endpoint. In your `config/routes.rb`, add
a `mount` at the endpoint you desire:

```ruby
Rails.application.routes.draw do
  mount Rapporteur::Engine, at: '/status'
end
```

This will mount the Rapporteur status endpoint at `/status` where it will
listen for and respond to JSON requests (`/status.json`, for example).

### Usage in a Rack (non-Rails) application

If you're running in a non-Rails, Rack environment (e.g. Sinatra), you can
`require "rapporteur"` and use the status generator directly from your own
endpoints.

So, here is an example usage in Sinatra:

```ruby
require "rapporteur"
require "sinatra/base"

class MyApp < Sinatra::Base
  get "/status.json" do
    content_type :json
    status(result.errors.empty? ? 200 : 500)
    body Rapporteur.run.as_json.to_json
  end
end
```

Require `rapporteur` and then, at some point, call `Rapporteur.run` to execute
{'fraction_non_alphanumeric': 0.09606319276340936, 'fraction_numerical': 0.017581857561472798, 'mean_word_length': 4.738304093567251, 'pattern_counts': {'":': 8, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4054356', 'n_tokens_mistral': 2494, 'n_tokens_neox': 2308, 'n_words': 935}