The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Plugging into Rails

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jamis Buck

Posts: 184
Nickname: minam
Registered: Oct, 2004

Jamis Buck is a C/Java software developer for BYU, and hacks in Ruby for fun.
Plugging into Rails Posted: Oct 11, 2005 2:36 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Jamis Buck.
Original Post: Plugging into Rails
Feed Title: the buckblogs here
Feed URL: http://weblog.jamisbuck.org/blog.cgi/programming/index.rss
Feed Description: Jamis Buck's corner of the blogging universe. Mostly about ruby, but includes ramblings on a variety of topics.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jamis Buck
Latest Posts From the buckblogs here

Advertisement

So, you’ve got a new acts_as_chunky_bacon mixin you want to add to ActiveRecord, but those villianous core team members have turned you down and called you unworthy. What other options do you have? People need this mixin. You understand that in Ruby, things ought to act like chunky bacon.

It used to be (in that dim age before the 2005 RubyConf) that your only recourse was to package the thing up and tell people to go through the hassle of putting your mixin somewhere, adding it to their load-path, and requiring the file.

No more! Edge Rails now sports a very-simple-but-effective plugin system. You, as the author, can now give someone a zip file and tell them to simply uncompress it into their vendor/plugins directory—and that’s it. No more configuration required by the user.

All you, as the author, need to do is create a project with the following directory structure:

  acts_as_chunky_bacon/
  acts_as_chunky_bacon/init.rb
  acts_as_chunky_bacon/lib
  acts_as_chunky_bacon/lib/acts_as_chunky_bacon.rb

When the application starts, the lib directory will be automatically added to the load path, and the init.rb automatically loaded. (Either may be absent.) The init.rb just needs to do something like the following:

  ActiveRecord::Base.send :include, ActsAsChunkyBacon

What does this mean? It means that consumers of your plugin only need to drop your project in their vendor/plugins directory, and then start applying it to their own model objects:

  class PoignantGuide < ActiveRecord::Base
    acts_as_chunky_bacon :from => "chapter 3" 
    ...
  end

Currently, we at 37signals are using this plugin system to share code between our various applications. We are using it for things like email notification on errors, or common before_filter’s, or our web service infrastructure that allows Backpack and Basecamp to integrate with Writeboard.

I really like this new plugin system. It probably isn’t perfect, yet—I’m sure people will find ways to make it even handier—but it really makes it a lot easier to share code. Hopefully it will also make it easier for the Rails core team to say “no” to many proposed new features, since many of them can now be more easily shared as third-party additions.

Read: Plugging into Rails

Topic: Surgeon General&rsquo;s Warning Previous Topic   Next Topic Topic: Two Days Until Ruby Code and Style Goes Live

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use