ActiveRecord::Like
An Active Record Plugin that allows chaining a more DSL-style 'like' or 'not-like' query to an ActiveRecord::Base#where. Requires Rails 5 or higher.
Status
This repo will no longer be the canonical repo for ActiveRecord::Like; the ownership of the gem has been transferred to @PikachuEXE which makes this the official repository.
History and credits
This plugin was originally salvaged from the stellar work done by @amatsuda and @claudiob.
- Most of the code was previously in Active Record master, but was subsequently removed due to, amongst other, scope creep (see discussion here).
- It was updated to ActiveRecord 5 by @PikachuEXE, then to ActiveRecord 5.2 by @robotdana and to ActiveRecord 6.1 by @nrw505.
- Array parameter handling was added by @rzane - thanks!
Installation
Add this line to your application's Gemfile:
gem 'activerecord-like'
And then execute:
$ bundle
Or install it yourself as:
$ gem install activerecord-like
Usage
Given a class Post and the WhereChain work in Active Record, this plugin allows code like:
Post.where.like(title: "%rails%")
Post.where.like(title: ["%ruby%", "%rails%"])
and
Post.where.not_like(title: "%rails%")
Post.where.not_like(title: ["%ruby%", "%rails%"])
Dependencies
ActiveRecord 5 or higher
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Make sure the tests run. I will not merge commits that change code without testing the new code. Running the tests is as easy as running
bundle && rake
- if this does not work, consider it a bug and report it. Testing with a specific database engine is done usingexport DB={engine}; bundle && rake
or the equivalent for your system. Supported engines aremysql
,sqlite3
andpg
. - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request