Favorites - A Ruby Gem
Speed-dial for your ActiveRecords! Set up shortcuts for commonly-accessed records so you can get them easily.
Tired of typing User.find_by_email("chris@arches.io") to get your user? Now you can get it directly with User.chris
Usage
- Include the library in your ActiveRecord class
- Set up your favorites with the
favoritemethod.
- First argument is the column to search, your favorite will forward to the
klass.find_by_<arg1>method - Second argument is the shortcut name, and the value to search against
class User < ActiveRecord::Base
include Favorites
favorite :email, {
chris: "chris@arches.io",
joe: "joe@joe.io"
}
end
- That's it! Now you can use your favorite in your code or console.
- In this example,
User.chriswill translate intoUser.find_by_email("chris@arches.io") - In this example,
User.joewill translate intoUser.find_by_email("joe@joe.io")