Project

that

0.0
No commit activity in last 3 years
No release in over 3 years
Adds a global method `that`, used to search across relevant fields for all available ActiveRecord models for matches for a string. Like running {Post,User,Comment}.find_by_{name,login,email}("foo")
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
 Project Readme

THAT

The Rails console all-purpose thing finding machine.

The GitHub Rails app has a nice helper method in the console called dat that gets you the right thing from an assortment of models based on a string. This is something similar intended for generic use (not based on the same implementation at all, i just wanted to be able to type dat :thedaniel in all my Rails apps).

Searches all AR models in a Rails app for matches to a string. Checks DEFAULT_TO_THAT_KEYS unless the model has a :to_that class method that returns an array of symbols to check against.

Returns the match if there's only one, otherwise an array of matches.

irb(main):001:0> that 'thedaniel'
  User Load (39.2ms)  SELECT "users".* FROM "users" WHERE "users"."name" = 'thedaniel'
  User Load (0.5ms)  SELECT "users".* FROM "users" WHERE "users"."login" = 'thedaniel'
  User Load (38.0ms)  SELECT "users".* FROM "users" WHERE "users"."email" = 'thedaniel'
  OtherModel Load (39.2ms)  SELECT "other_models".* FROM "other_models" WHERE "other_models"."specified_field" = 'thedaniel'
  OtherModel Load (0.5ms)  SELECT "other_models".* FROM "other_models" WHERE "other_models"."other_field" = 'thedaniel'
=> #<User id: 167035, login: "thedaniel">

Call That.activate to monkey patch Object and make it work.

I personally use this .irbrc:

if defined?(Rails) && defined?(That)
  That.activate
end