Project

saringan

0.0
No commit activity in last 3 years
No release in over 3 years
Simple way to send filter parameters to rails models.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Saringan ยท Build Status GitHub license Gem Version

Translate query strings to activerecord query parameters.

Installation

Add this line to your application's Gemfile:

gem 'saringan'

And then execute:

$ bundle

Or install it yourself as:

$ gem install saringan

Usage

Use Saringan::Translator to translate query string to activerecord parameters:

irb> query = "name::John"
irb> Saringan::Translator.translate(query)
{ name: 'John' }

Operators

Obs.: This is a preliminar version, so others operators will be implemented in future versions.

Equals

This handle absolute equals query like "WHERE name = 'John'". To do it you must use Saringan equals operator '::'

In URL: http://site.com?query=name::John

In code:

irb> query = params[:query]
irb> Saringan::Translator.translate(query)
{ name: 'John' }

Parsers

Obs.: This is a preliminar version, so others parsers will be implemented in future versions.

String Parser

Just pass value without any qualifier

Date Time Parser

Pass value using Saringan Date Time qualifier. Saringan will parse value to DateTime object. It expect date time in '%Y-%m-%d %H:%M:%S' format, see:

In URL: http://site.com?query=starts_at::dt[2018-06-30 00:00:00]

In code:

irb> query = params[:query]
irb> Saringan::Translator.translate(query)
{ starts_at: DateTime object }
Range

Pass value using Saringan range operator '|'

In URL: http://site.com?query=starts_at::dt[2018-06-30 00:00:00|2018-06-30 23:59:59]

In code:

irb> query = params[:query]
irb> Saringan::Translator.translate(query)
{ starts_at: DateTime object..DateTime object }

License

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