Thor is a simple and efficient tool for building self-documenting command line utilities. It removes the pain of parsing command line options, writing “USAGE:” banners, and can also be used as an alternative to the Rake build tool. The syntax is Rake-like, so it should be familiar to most Rake users.
I have built a corporate security model. When I say “security model” I am talking in a generic fashion. So what is it? Well it is ER-model for a relational database which allows me to record people objects, their web user objects, the organization objects that they belong to, the role objects for web app usage rights, and many other objects related to general web application use by humans.
When implementing such a model in an MVC architecture like RubyOnRails there will be many files located in various directories. This is not a big problem at all until you decide that you want to use this security model’s functionality in other RubyOnRails web applications. The obvious solution is to build some kind of plugin. Indeed, frameworks such as RubyOnRails do provide some sort of support for building plugins that can be reused.
In the Ruby development world we have the excellent Rake build and automation tool. However, this article will explore Thor which can be considered a kind of “next generation” Rake tool.
I’ll keep this post short and explore more details at a later time. For now let’s take a look at my Thor “configuration.”
...dev/_thor/testarea$ thor installed
thor authena:install NAMEs files #
thor authena:removes installed files #
thor fbp_tools:install NAME # installs files
thor fbp_tools:uninstall NAME # removes installed files
We see that there are two Thor packages installed in my environment. I built them both. Authena is the name of the Thor task package which installs and uninstalls the security model files. fbp_tools is the package which installs some utility files which I use in many Rails apps.
Both packages install and remove files into various directories such as the “models”, “views”, and “controllers” directories.
Let me finish with a teaser showing you what happens when we install the Authena package. Next time, I’ll dig into the code a bit deeper.
...testarea$ thor authena:install
As you can image it would be very time consuming to copy these files manually every time you want to add this module to your MVC application!!!
Removing this security model’s files is quite easy as well:
.../testarea$ thor authena:uninstall