About a year ago I was working with an ActiveRecord model, and for some reason things would blow up when I tried to do anything to this model inside rake. Turns out having a field called 'link' was a very bad idea, given the rake code bel
1 2 3 4 5 6 7 8 9 10 | # ########################################################################### # Include the FileUtils file manipulation functions in the top level module, # but mark them private so that they don't unintentionally define methods on # other objects. include RakeFileUtils private(*FileUtils.instance_methods(false)) private(*RakeFileUtils.instance_methods(false)) ################################################################## |
The problem is our friend "send" and the fact that it could care less about the call to private. This cost me the better part of a night, and I guess I've never really forgiven rake for it...
Enter thor. If you haven't heard of this, take a look
here and see what you think. The code is practically 100% covered by specs, and is easy to dive into...and something just feels better about defining plain old ruby methods instead of tasks.
So, in the interest of learning thor better, I took the merb sake tasks and converted them to their thor equivalents. The end result is found at
http://github.com/jackdempsey/merb-thor/tree/master and once you have thor installed you should install the file with
1 | $ thor install http://github.com/jackdempsey/merb-thor/tree/master%2Fmerb.thor?raw=true --as=merb |
The --as option lets you name things nicely so in the future you can do
to get any new stuff thats added in.
I'm happy to take comments, updates, patches, etc. Enjoy!
UpdateThere appears to be a small bug with namespacing of commands. For the time being, all of the commands should work if you run them inside a directory where merb.thor exists. I hope to have this fixed over the next few days, but til then, this should be a quick solution.
Update Part DeuxI've created a fork of thor in a branch you can find at:
http://github.com/jackdempsey/thor/tree/constantsIf you install from here thor will load all .thor files it finds in your root whether they're relevant or not. This will get around the constants issue preventing things like 'thor merb:gems:refresh' from working.
Update Part FinaleSo merb-thor has grown up and become part of the merb stack. I've updated the repo to point to the new goodness, but if you're reading this you can go there directly:
http://merbunity.com/tutorials/18
Much thanks to those who've shown interest in it, sent me patches, etc, I appreciate it. I'll be working on new and exciting stuff with Thor in the future, and if you have thoughts/ideas on things like http://github.com/jackdempsey/self-deprecated let me know!