I’m all for skinny controllers, but fat models can get unmanageable. After adding a couple of methods for this, that and the other – perhaps a User with authorization, password reset and serialization – the model can be quite fat indeed.
There are many conceivable ways of making fat models more manageable. Something very simple I’ve been trying lately is to just group code in blocks, and fold them in TextMate as needed. The simplest way is to just use begin/end:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
I prefer self-documenting code to comments, though. You can fake it by doing
1 2 3 | |
The :authentication symbol isn’t actually a method argument – this is equivalent to
1 2 3 4 | |
so I suppose whether it can be described as more self-documenting than comments is debatable.
:foo.code do
Anyway, I do this instead:
As lib/ar_groups.rb:
1 2 3 4 5 | |
Added to config/environment.rb:
1
| |
And then you can do:
1 2 3 4 5 6 7 8 9 10 11 | |
category :foo do
If abusing symbols bothers you, try something like
1 2 3 4 5 6 7 8 | |
and
1 2 3 4 5 6 7 8 9 10 11 | |
Highlighting
To make things more manageable still, TextMate can be made to highlight these blocks. Merge this rule into the Ruby grammar (with thanks to Ciarán Walsh):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | |
and theme source.ruby meta.code-cat to taste. Et voilà:
![[Screenshot]](http://henrik.nyh.se/uploads/ar-categories_tm.png)
Adapting the grammar for other kinds of blocks should be pretty straightforward.