<?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 Rails Plugins: Will somebody PLEASE think of the children?</title>
    <link>http://somethinglearned.com/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>something learned comments</description>
    <item>
      <title>"Rails Plugins: Will somebody PLEASE think of the children?" by trevor</title>
      <description>&lt;p&gt;First of all, if plugins are new to you then you should definitely look at &lt;a href="http://www.jamis.jamisbuck.org/articles/2005/10/11/plugging-into-rails"&gt;Jamis Buck&amp;#8217;s guide to plugins&lt;/a&gt; before going any further.&lt;/p&gt;


	&lt;p&gt;Okay, so by now you know everything about plugins right?&lt;/p&gt;


	&lt;p&gt;So, I had one of those &amp;#8216;uh-oh&amp;#8217; moments last night.&lt;/p&gt;


	&lt;h3&gt;The Issue&lt;/h3&gt;


	&lt;p&gt;I was worried that putting my &lt;code&gt;acts_as_enumerated&lt;/code&gt; into &lt;code&gt;ActiveRecord::Acts::Enumerated&lt;/code&gt; was a bad idea.  I emailed Jamis and asked if plugin authors should avoid any rails module namespaces and he said:&lt;/p&gt;


&lt;blockquote&gt;
That&amp;#8217;s a really interesting question. I think I would answer &amp;#8220;Yes&amp;#8221;, but I&amp;#8217;m not sure why. :)

	&lt;p&gt;It feels more natural to me if people follow a naming convention similar to how things are done in Javaland, where modules are namespaced by their vendor. So:&lt;/p&gt;


	&lt;p&gt;TrevorSquires::Acts::Enumerated&lt;/p&gt;


or something :)
&lt;/blockquote&gt;

	&lt;p&gt;He went on to point out that right now there are no guidelines or best practices.&lt;/p&gt;


	&lt;p&gt;Considering the number of plugins that have &lt;a href="http://wiki.rubyonrails.org/rails/pages/Plugins"&gt;already been written&lt;/a&gt; it&amp;#8217;s probably a good idea to start thinking about this now.&lt;/p&gt;


	&lt;h3&gt;The Opinion&lt;/h3&gt;


	&lt;p&gt;So here&amp;#8217;s my opinion, presented in a way that I hope everyone from newbies (like me), to seasoned pros can understand.  I&amp;#8217;d appreciate feedback from others on this.&lt;/p&gt;


	&lt;p&gt;A plugin author has two namespaces to be concerned about:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;code&gt;$LOAD_PATH&lt;/code&gt;&lt;/li&gt;
		&lt;li&gt;Modules&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;The two namespaces kind-of overlap, but they don&amp;#8217;t &lt;em&gt;have&lt;/em&gt; to.  I have a file called &lt;code&gt;/lib/active_record/virtual_enumerations.rb&lt;/code&gt; that defines a &lt;code&gt;ActiveRecord::VirtualEnumerations&lt;/code&gt; module &lt;em&gt;and&lt;/em&gt; re-opens the ruby &lt;code&gt;Module&lt;/code&gt; class.  The name of the file doesn&amp;#8217;t have to dictate its contents.&lt;/p&gt;


	&lt;p&gt;But the name of the file plays a role in being able to load your code in the first place &amp;#8211; via the &lt;code&gt;require&lt;/code&gt; keyword.  If there are two plugins that have a &lt;code&gt;/lib/chunky_bacon.rb&lt;/code&gt; file then &lt;code&gt;require 'chunky_bacon'&lt;/code&gt; will load the first one found in &lt;code&gt;$LOAD_PATH&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;Now, as long as your &lt;code&gt;init.rb&lt;/code&gt; does a &lt;code&gt;require&lt;/code&gt; of all necessary files during initialization this won&amp;#8217;t be an issue because during init &lt;em&gt;your&lt;/em&gt; plugin&amp;#8217;s &lt;/code&gt;/lib&lt;/code&gt; directory is the first one in &lt;code&gt;$LOAD_PATH&lt;/code&gt;.&lt;/p&gt;


	&lt;p&gt;However, it may become an issue if you, or any other package that happens to &lt;code&gt;require 'chunky_bacon'&lt;/code&gt;, decide to defer &lt;code&gt;require&lt;/code&gt; calls until a later time.&lt;/p&gt;


	&lt;p&gt;Even though for most people the &lt;code&gt;$LOAD_PATH&lt;/code&gt; won&amp;#8217;t be an issue, I believe plugin authors should be encouraged to use a directory structure, unique to themselves, within their &lt;/code&gt;/lib&lt;/code&gt; directory.  Using someone else&amp;#8217;s plugin for an example:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
/lib/techno_weenie/acts_as_paranoid.rb
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Not only does it solve potential &lt;code&gt;$LOAD_PATH&lt;/code&gt; problems but it also serves as a reminder that you really ought to make your Module namespaces unique as well (as Jamis said above).&lt;/p&gt;


	&lt;p&gt;Comments?&lt;/p&gt;

</description>
      <pubDate>Wed, 26 Oct 2005 12:33:00 EDT</pubDate>
      <guid>&lt;a href="/articles/2005/10/26/rails-plugins-will-somebody-please-think-of-the-children"&gt;Rails Plugins: Will somebody PLEASE think of the children?&lt;/a&gt;</guid>
      <link>&lt;a href="/articles/2005/10/26/rails-plugins-will-somebody-please-think-of-the-children"&gt;Rails Plugins: Will somebody PLEASE think of the children?&lt;/a&gt;</link>
    </item>
  </channel>
</rss>

