Section 6.4. Distributing Your Plugins as RubyGems


6.4. Distributing Your Plugins as RubyGems

While it is easy to type your handlers into a -S mongrel.conf, this isn't an easy way to distribute your handlers and it'll break down if you need extras to go along with them. The preferred way to package up a Mongrel plugin and distribute it to people is to use the GemPlugin system.

GemPlugin is a dynamic plugin loading system based entirely on RubyGems. It's very simple to use and comes with a full project generator to get you started. GemPlugin makes it possible for people to extend Mongrel without including their source in Mongrel, and to distribute them in a way that's familiar to most Ruby users.

Explaining how GemPlugin works probably isn't going to be helpful since it digs into the RubyGems API. Instead, we'll do a quick demonstration of the PFM[11] in action. Take your install of Mongrel and make sure you remove the mongrel_cluster gem:

[11] Pure F***ing Magic. The best kind of magic (http://en.wikipedia.org/wiki/PFM).

$ sudo gem uninstall mongrel_cluster $ mongrel_rails Usage: mongrel_rails <command> [options] Available commands are:  - console  - restart  - start  - stop  - status Each command takes -h as an option to get help.


Notice the list of commands when you run the mongrel_rails command? Add the mongrel_cluster gem back to your system and run mongrel_rails again and you'll see this list of commands:

- cluster::configure - cluster::restart - cluster::start - cluster::stop - console - restart - start - stop - status


Now you get all these new commands like magic. No, like PFM. How's that work? The simplest explanation is that GemPlugin goes through the list of gems installed in your system and tries to find gems that depend on the mongrel gem. When it does, it requires the gem and runs an init.rb file if present.

With this simple system, Mongrel will then autoload any plugins you install as gems. We'll go through two examples of doing a GemPlugin in the next few sections.

6.4.1. Using Rubyforge to Share

When you've crafted a nice GemPlugin and you want to share it with the world, you should pop over to http://www.rubyforge.org/ and register a project. When you do this you can upload your .gem file to their file service and then the RubyGems mirrors will pick it up.




Mongrel. Serving, Deploying, and Extending Your Ruby Applications
Mongrel. Serving, Deploying, and Extending Your Ruby Applications
ISBN: 9812836357
EAN: N/A
Year: 2006
Pages: 48

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net