<commit_before># Parelation

[![Gem Version](https://badge.fury.io/rb/parelation.svg)](http://badge.fury.io/rb/parelation)
[![Code Climate](https://codeclimate.com/github/meskyanichi/parelation.png)](https://codeclimate.com/github/meskyanichi/parelation)
[![Build Status](https://travis-ci.org/meskyanichi/parelation.svg)](https://travis-ci.org/meskyanichi/parelation)

Parelation, for Rails/ActiveRecord 4.1.0+, allows you to query your ActiveRecord-mapped database easily, securely and quite flexibly using simple GET requests. It's used in your controller layer where it uses HTTP GET parameters to build on the ActiveRecord::Relation chain. This provides the client-side with the out-of-the-box flexibility to perform fairly dynamic queries without having to write boilerplate on the server.

This library was developed for- and extracted from [HireFire].

The documentation can be found on [RubyDoc].

### Compatibility

- Rails/ActiveRecord 4.1.0+
- Ruby (MRI) 2.0+
- Ruby (RBX) 2.2+

### Installation

Add the gem to your Gemfile and run `bundle`.

```rb
gem "parelation"
```

*This library won't be hosted on RubyGems.org until it's been tested more in development.*

### Example

Here's an example to get an idea of how it works. We'll fetch the `50` most recently created and `open` tickets, and we only want their `id`, `name` and `message` attributes.

```js
var params = {
  "select[]": ["id", "name", "message"],
  "where[state]": "open",
  "order": "created_at:desc",
  "limit": "50"
}

$.get("https://api.ticket.app/tickets", params, function(tickets){
  console.log("Just fetched the 50 most recent and open tickets.")
  $.each(tickets, function(ticket){
    console.log("Ticket " + ticket.name + " loaded!")
  })
})
```

Simply include `Parelation::Helpers` and use the `parelate` method. This will ensure that the provided parameters are converted and applied to the `Ticket.all` criteria chain.

```rb
class Api::V1::TicketsController < ApplicationController
  include Parelation::Helpers

  def index
    render json: parelate(Ticket.all)<commit_msg>Remove notice that states that the gem isn't hosted on RubyGems.org. It is hosted on RubyGems.org now.<commit_after># Parelation

[![Gem Version](https://badge.fury.io/rb/parelation.svg)](http://badge.fury.io/rb/parelation)
[![Code Climate](https://codeclimate.com/github/meskyanichi/parelation.png)](https://codeclimate.com/github/meskyanichi/parelation)
[![Build Status](https://travis-ci.org/meskyanichi/parelation.svg)](https://travis-ci.org/meskyanichi/parelation)

Parelation, for Rails/ActiveRecord 4.1.0+, allows you to query your ActiveRecord-mapped database easily, securely and quite flexibly using simple GET requests. It's used in your controller layer where it uses HTTP GET parameters to build on the ActiveRecord::Relation chain. This provides the client-side with the out-of-the-box flexibility to perform fairly dynamic queries without having to write boilerplate on the server.

This library was developed for- and extracted from [HireFire].

The documentation can be found on [RubyDoc].

### Compatibility

- Rails/ActiveRecord 4.1.0+
- Ruby (MRI) 2.0+
- Ruby (RBX) 2.2+

### Installation

Add the gem to your Gemfile and run `bundle`.

```rb
gem "parelation"
```


### Example

Here's an example to get an idea of how it works. We'll fetch the `50` most recently created and `open` tickets, and we only want their `id`, `name` and `message` attributes.

```js
var params = {
  "select[]": ["id", "name", "message"],
  "where[state]": "open",
  "order": "created_at:desc",
  "limit": "50"
}

$.get("https://api.ticket.app/tickets", params, function(tickets){
  console.log("Just fetched the 50 most recent and open tickets.")
  $.each(tickets, function(ticket){
    console.log("Ticket " + ticket.name + " loaded!")
  })
})
```

Simply include `Parelation::Helpers` and use the `parelate` method. This will ensure that the provided parameters are converted and applied to the `Ticket.all` criteria chain.

```rb
class Api::V1::TicketsController < ApplicationController
  include Parelation::Helpers

  def index
    render json: parelate(Ticket.all)
{'fraction_non_alphanumeric': 0.13115942028985508, 'fraction_numerical': 0.00821256038647343, 'mean_word_length': 4.759388038942976, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 12, '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': '4566473', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1281, 'n_words': 433}