The extra module was their to facilitate testing but now that
everything is properly namespaced and each command is an instance
we can just move the methods into the command. Since it's an
instance now we don't need to be as careful about caching either.
This wasn't working before for a few reasons.
1. It never got past the installed name check because the
installed name sets had short names and the tap names were
long names including the tap namespace too. Now we just trim the
long name before comparing it to the installed name set.
Before:
```
["name"].include?("tap/full/name") # always false
```
After:
```
["name"].include("tap/full/name".split("/").last) # sometimes true
```
2. The names we were trying to load formulae and casks with
were incorrect.
Before:
```
tap = Tap.fetch("homebrew/cask-versions")
token = "homebrew/cask-versions/token"
cask = Cask::CaskLoader.load("#{tap}/#{token}")
```
After:
```
token = "homebrew/cask-versions/token"
cask = CaskCaskLoader.load(token)
```
If an installed cask is invalid on attempting an untap: it will
prevent untapping that cask.
Fix this in two ways: one more specific to `untap` and one more
generally to other commands too:
- specific: only read the actual formulae/casks from the tap we're
untapping instead of all of those that are installed
- general: rescue more exceptions in `Cask::Caskroom.casks` (like we
already do for `Formula.installed`
There are plenty of IO operations inside Tap object, and it will be more
when implementing formula alias reverse look up(e.g. list all of alias
names for a formula). So let's cache them.
Some benchmark:
$ time brew info $(brew ruby -e 'puts Formula.tap_names') > /dev/null
Before: 6.40s user 2.42s system 96% cpu 9.134 total
After: 4.75s user 0.77s system 97% cpu 5.637 total
ClosesHomebrew/homebrew#44377.
Signed-off-by: Xu Cheng <xucheng@me.com>