sferik/t — pull request #51 by brookr (2012-05-28 06:37:39+00:00)
Title: Allow loose match when setting account

Hi! Love the gem! Thank you for maintaining.

I hit an error when switching accounts... I'm too lazy to type the username exactly, with correct case, so here's a little patch to allow easier account switching.

I tried to follow the style of what I saw in the project, but I certainly won't be offended if you want to refactor or tweak any parts of this. You may have a different philosophy for method naming, or whatever.

In any event, hope it's useful!

Thanks again.

—Brook R

Commit details:

Previously, trying to set an account without exactly matching the account
name (case-sensitive) resulted in an unsightly NoMethodError:

gems/t-0.9.9/lib/t/set.rb:21:in keys' for nil:NilClass (NoMethodError)

With this change, we can be a little smarter about handling the user's input.
-- Usernames are now stored downcased, since Twitter doesn't care
-- Activating an account will attempt an exact match first
-- If exact match fails, a case-insensitve loose match will be attempted
-- If the loose match fails, a sensible error message will be displayed.

To get this to work, I had to dig a little deeper into the .trc file to get the
downcased, complete version of the username (@rcfile[screen_name][consumer_key][username]),
when setting @rcfile.active_profile. Hopefully this is the correct way to do so.

A few additional specs to cover this added funcitonality are included.