Skip to content

Parse filters (or something else) from pretty human readable query string to hash

License

Notifications You must be signed in to change notification settings

bsedin/query_filters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QueryFilters

Hello there! You can use this tiny library to parse pretty query strings to pretty hashes or arrays.

Installation

Add this line to your application's Gemfile:

gem 'query_filters'

And then execute:

$ bundle

Or install it yourself as:

$ gem install query_filters

Usage

QueryFilters.parse('date_gteq=20-11-2018,date_lteq=20-12-2018')

Produces:

{ date_gteq: '20-11-2018', date_lteq: '20-12-2018' }

Nested params

QueryFilters.parse('date_gteq=20-11-2018,date_lteq=20-12-2018,posts:title=what about dogs,posts:order=date_desc')

Produces:

{
  date_gteq: '20-11-2018',
  date_lteq: '20-12-2018',
  posts: { title: 'what about dogs', order: 'date_desc' }
}

Configuration

You can configure parser through options:

QueryFilters.parse('posts/title:what about dogs;posts/order:title_desc',
  nesting_separator: '/',
  assignment_separator: ':',
  filters_separator: ';',
  symbolize_keys: false
)

Produces:

{"posts"=>{"title"=>"what about dogs", "order"=>"title_desc"}}

Default options are:

  • nesting_separator :
  • assignment_separator =
  • filters_separator ,
  • symbolize_keys true

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

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

License

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

About

Parse filters (or something else) from pretty human readable query string to hash

Resources

License

Stars

Watchers

Forks

Packages

No packages published