All Projects → BaseSecrete → Type_scopes

BaseSecrete / Type_scopes

Automatic scopes for ActiveRecord models.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Type scopes

nxt state machine
A simple but powerful state machine implementation.
Stars: ✭ 14 (-41.67%)
Mutual labels:  activerecord, ruby-on-rails
Filterrific
Filterrific is a Rails Engine plugin that makes it easy to filter, search, and sort your ActiveRecord lists.
Stars: ✭ 810 (+3275%)
Mutual labels:  activerecord, ruby-on-rails
activerecord-cockroachdb-adapter
CockroachDB adapter for ActiveRecord.
Stars: ✭ 90 (+275%)
Mutual labels:  activerecord, ruby-on-rails
active record-updated at
Touch `updated_at` by default with calls to `update_all` and `update_column(s)`
Stars: ✭ 27 (+12.5%)
Mutual labels:  activerecord, ruby-on-rails
Database validations
Database validations for ActiveRecord
Stars: ✭ 274 (+1041.67%)
Mutual labels:  activerecord, ruby-on-rails
prefixed ids
Friendly Prefixed IDs for your Ruby on Rails models
Stars: ✭ 159 (+562.5%)
Mutual labels:  activerecord, ruby-on-rails
rails cursor pagination
Add cursor pagination to your ActiveRecord backed application
Stars: ✭ 21 (-12.5%)
Mutual labels:  activerecord, ruby-on-rails
Model probe
Schema introspection for ActiveModel
Stars: ✭ 58 (+141.67%)
Mutual labels:  activerecord, ruby-on-rails
Elasticsearch Rails
Elasticsearch integrations for ActiveModel/Record and Ruby on Rails
Stars: ✭ 2,896 (+11966.67%)
Mutual labels:  activerecord, ruby-on-rails
LocalSupport
A directory of local support services and volunteer opportunities
Stars: ✭ 60 (+150%)
Mutual labels:  activerecord, ruby-on-rails
activerecord-crate-adapter
Ruby on Rails ActiveRecord adapter for CrateDB
Stars: ✭ 27 (+12.5%)
Mutual labels:  activerecord, ruby-on-rails
Ransack
Object-based searching.
Stars: ✭ 5,020 (+20816.67%)
Mutual labels:  activerecord, ruby-on-rails
Octopus
Database Sharding for ActiveRecord
Stars: ✭ 2,496 (+10300%)
Mutual labels:  activerecord, ruby-on-rails
activerecord-setops
Union, Intersect, and Difference set operations for ActiveRecord (also, SQL's UnionAll).
Stars: ✭ 21 (-12.5%)
Mutual labels:  activerecord, ruby-on-rails
Active record Events
Manage timestamps in ActiveRecord models
Stars: ✭ 109 (+354.17%)
Mutual labels:  activerecord, ruby-on-rails
squint
Search PostgreSQL jsonb and hstore columns
Stars: ✭ 26 (+8.33%)
Mutual labels:  activerecord, ruby-on-rails
Goldiloader
Just the right amount of Rails eager loading
Stars: ✭ 1,074 (+4375%)
Mutual labels:  activerecord, ruby-on-rails
filtered
Filters ActiveRecord queries in a nice way
Stars: ✭ 28 (+16.67%)
Mutual labels:  activerecord, ruby-on-rails
Database consistency
The tool to find inconsistency between models schema and database constraints.
Stars: ✭ 418 (+1641.67%)
Mutual labels:  activerecord, ruby-on-rails
Active Record Query Trace
Rails plugin that logs/displays a backtrace of all SQL queries executed by Active Record
Stars: ✭ 785 (+3170.83%)
Mutual labels:  activerecord, ruby-on-rails

Type Scopes

Type scopes creates useful scopes based on the type of the columns of your models. It handles dates, times, strings and numerics.

Here is an example of all the available scopes:

# paid_at: datetime
# amount: decimal
# description: string
class Transaction < ActiveRecord::Base
  include TypeScopes
end

# Time scopes
Transaction.paid_to("2017-09-06") # => where("paid_at <= '2017-09-06'")
Transaction.paid_from("2017-09-06") # => where("paid_at >= '2017-09-06'")
Transaction.paid_after("2017-09-06") # => where("paid_at > '2017-09-06'")
Transaction.paid_before("2017-09-06") #= where("paid_at < '2017-09-06'")
Transaction.paid_between("2017-09-06", "2017-09-07")  # => where("paid_at BETWEEN '2017-09-06' AND '2017-09-07'")

# Numeric scopes
Transaction.amount_to(100) # => where("amount <= 100")
Transaction.amount_from(100) # => where("amount >= 100")
Transaction.amount_above(100) # => where("amount > 100")
Transaction.amount_below(100) # => where("amount < 100")
Transaction.amount_between(100, 200) # => where("amount BETWEEN 100 AND 200")

# String scopes
Transaction.description_contains("foo") # => where("description LIKE '%foo%'")
Transaction.description_starts_with("foo") # => where("description LIKE 'foo%'")
Transaction.description_ends_with("foo") # => where("description LIKE '%foo'")

# Boolean scopes
Transaction.non_profit # => where("non_profit = true")
Transaction.not_non_profit # => where("non_profit = false")
Transaction.is_valid # => where("is_valid = true")
Transaction.is_not_valid # => where("is_valid = false")
Transaction.has_payment # => where("has_payment = true")
Transaction.has_not_payment # => where("has_payment = false")
Transaction.was_processed # => where("was_processed = true")
Transaction.was_not_processed # => where("was_processed = false")

For the string scope the pattern matching is escaped:

Transaction.description_contains("%foo_") # => where("description LIKE '%[%]foo[_]%'")

Install

Add to your Gemfile:

gem "type_scopes"

And run in your terminal:

bundle install

Then include TypeScopes from your models:

class Transaction < ActiveRecord::Base
  include TypeScopes
end

MIT License

Made by Base Secrète.

Rails developer? Check out RoRvsWild, our Ruby on Rails application monitoring tool.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].