0.0
No release in over 3 years
Low commit activity in last 3 years
Generate automatically scopes in your model (PostgreSQL, SQLite, MySQL, etc...)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 0.8
~> 2.13
~> 1.2
~> 13.0
~> 3.0
~> 0.16

Runtime

>= 5.2, < 7
 Project Readme

RailsScopy

Gem Version Maintainability Build Status security Gem Coverage Status

Generate automatically scopes in your model (PostgreSQL, SQLite, MySQL, etc...)

Installation

Add this line to your application's Gemfile:

gem 'rails_scopy'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rails_scopy

Usage

Include RailsScopy in each models

class User < ApplicationRecord
  include RailsScopy
end

or in the parent model

class ApplicationRecord < ActiveRecord::Base
  include RailsScopy
end

and

User.not_admin

User.first_name_contains('Test')

Scopes available

SQL type Scope method Description
All #{column}_eq(value) equal
All #{column}_not_eq(value) not equal
All #{column}_null is null
All #{column}_not_null is not null
All #{column}_present not null and not empty
All #{column}_blank null or empty
All ascend_by_#{column} ascending order
All descend_by_#{column} descending order
boolean #{column} true
boolean not_#{column} false
json #{column}_has_key(value) key present in json
json not_#{column}_has_not_key(value) key doesn't present in json
boolean #{column} true
boolean not_#{column} false
date, datetime, time #{column}_to(value) <= to
date, datetime, time #{column}_from(value) from >=
date, datetime, time #{column}_after(value) after >
date, datetime, time #{column}_before(value) < before
date, datetime, time #{column}_between(value) from >= <= to
string, text #{column}_contains(value) contains
string, text #{column}_not_contains(value) doesn't contains
string, text #{column}_starts_with(value) start with
string, text #{column}_not_starts_with(value) doesn't start with
string, text #{column}_ends_with(value) end with
string, text #{column}_not_ends_with(value) doesn't end with
string, text #{column}_length(value) length eql
string, text #{column}_between_length(value) from >= <= to (length)
integer, float #{column}_to(value) <= to
integer, float #{column}_from(value) from >=
integer, float #{column}_above(value) above >
integer, float #{column}_below(value) < below
integer, float #{column}_between(value) from >= <= to
float #{column}_scale(value) scale eql (Number of decimal digits)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/OpenGems/rails_scopy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

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