Project

brita

0.04
No release in over 3 years
Low commit activity in last 3 years
Easily write arbitrary filters
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
>= 5.1
>= 0

Runtime

> 4.2.0
 Project Readme

Sift

Tests

A declarative DSL for building filters and sorts with Rails and Active Record.

Usage

Include Sift in your controllers and define filters and sorts:

class PostsController < ApplicationController
  include Sift

  filter_on :title, type: :string
  filter_on :priority, type: :int
  filter_on :published_at, type: :datetime
  filter_on :with_body, type: :scope

  sort_on :title, type: :string
  sort_on :priority, type: :int

  before_action :render_filter_errors, unless: :filters_valid?

  def index
    render json: filtrate(Post.all)
  end

  private

  def render_filter_errors
    render json: { errors: filter_errors }, status: :bad_request
  end
end

Consumers can then filter and sort via query parameters:

GET /posts?filters[title]=hello&filters[priority]=1...5&sort=-published_at,title

Installation

Add this line to your application's Gemfile:

gem 'procore-sift'

And then execute:

$ bundle

Documentation

  • Filters - Filter types, scopes, ranges, JSONB, defaults, validation
  • Sorts - Sort types and scope-based sorting
  • Consumer API - Query parameter format for API consumers
  • Contributing - Development setup and publishing

Changelog

See CHANGELOG.md for release notes.

License

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

About Procore

Procore Logo

The Procore Gem is maintained by Procore Technologies.

Procore - building the software that builds the world.

Learn more about the #1 most widely used construction management software at procore.com