<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>something learned comments on Announcement: New Rails Plugin</title>
    <link>http://www.somethinglearned.com/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>something learned comments</description>
    <item>
      <title>"Announcement: New Rails Plugin" by trevor</title>
      <description>&lt;p&gt;I&amp;#8217;m pleased to announce the release of a new rails plugin for ActiveRecord, chock full o&amp;#8217;goodness from:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;acts_as_enumerated&lt;/li&gt;
		&lt;li&gt;has_enumerated&lt;/li&gt;
		&lt;li&gt;ActiveRecord::VirtualEnumerations&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;What is it?&lt;/h3&gt;


	&lt;p&gt;As part of the work I&amp;#8217;ve been doing at &lt;a href="http://engineering.site5.com"&gt;Site5.com&lt;/a&gt; (who have very graciously allowed me to release this code into the wild) I put together an extension to treat an ActiveRecord model as an enumeration.  I.e.:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
class BookingStatus &amp;lt; ActiveRecord::Base
  acts_as_enumerated, :order =&amp;gt; 'position ASC'
end

booking.status = BookingStatus[:confirmed]
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Values for acts_as_enumerated models are cached (reducing hits to the database) and you can define &amp;#8216;virtual&amp;#8217; acts_as_enumeration classes, eliminating the need to clutter your models directory with classes that do nothing more than acts_as_enumerated.&lt;/p&gt;


	&lt;p&gt;The has_enumerated macro allows your models to refer to acts_as_enumerated instances without resorting to using belongs_to (which can require you to jump through hoops to avoid the database hit when retrieving the enumeration value).&lt;/p&gt;


	&lt;p&gt;I should point out that this isn&amp;#8217;t the first time something like this has been done.  Michael Shuerig sent a &lt;a href="http://thread.gmane.org/gmane.comp.lang.ruby.rails/19193"&gt;mail&lt;/a&gt; to the rails list a while back (when I was first looking at this feature) outlining how he was adding enumerations to his Boilerplate library.&lt;/p&gt;


	&lt;p&gt;Boilerplate&amp;#8217;s enumerations differ from this plugin in some pretty significant ways but Michael&amp;#8217;s technique of hooking into Module.const_missing was the missing piece of the puzzle I needed to eliminate clutter in the models directory &amp;#8211; I&amp;#8217;m very grateful for that.&lt;/p&gt;


	&lt;h3&gt;How is it installed?&lt;/h3&gt;


	&lt;p&gt;Well, the new rails &amp;#8216;plugins&amp;#8217; feature makes packaging and releasing extensions a &lt;strong&gt;lot&lt;/strong&gt; more straight forward.&lt;/p&gt;


	&lt;p&gt;First of all, you need to be running a plugin-compatible version of rails (0.14 and above).  Then you simply:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
cd vendor/plugins
svn export http://svn.protocool.com/rails/plugins/enumerations_mixin/trunk \
   enumerations_mixin
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The &lt;span class="caps"&gt;README&lt;/span&gt;_ENUMERATIONS file should be enough to get you started &amp;#8211; when I manage to scrape together some spare time I&amp;#8217;ll insert some (hopefully) more helpful rdoc.&lt;/p&gt;


	&lt;h3&gt;What&amp;#8217;s missing?&lt;/h3&gt;


	&lt;p&gt;Well, proper documentation, for a start.  Apart from that it&amp;#8217;s fully functional.&lt;/p&gt;


	&lt;p&gt;Enjoy!&lt;/p&gt;

</description>
      <pubDate>Tue, 25 Oct 2005 16:33:39 EDT</pubDate>
      <guid>&lt;a href="/articles/2005/10/25/announcement-new-rails-plugin"&gt;Announcement: New Rails Plugin&lt;/a&gt;</guid>
      <link>&lt;a href="/articles/2005/10/25/announcement-new-rails-plugin"&gt;Announcement: New Rails Plugin&lt;/a&gt;</link>
    </item>
  </channel>
</rss>
