<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 <title>Tom Ward</title>
 <link href="http://tomafro.net/atom.xml" rel="self"/>
 <updated></updated>
 <id>http://tomafro.net/</id>
 <author>
   <name>Tom Ward</name>
   <email>tom@popdog.net</email>
 </author>
 
 <entry>
   <id>http://tomafro.net</id>
   <link href="http://tomafro.net/2009/07/salvador-dali-on-whats-my-line"/>
   <title>Salvador Dali on "What's My Line?"</title>
   <author>
     <name>Tom Ward</name>
     <email>tom@popdog.net</email>
   </author>
   <content type="html">&lt;p class=&quot;video&quot;&gt;
&lt;object width=&quot;800&quot; height=&quot;630&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/iXT2E9Ccc8A&amp;amp;hl=en&amp;amp;fs=1&amp;amp;rel=0&amp;amp;color1=0x3a3a3a&amp;amp;color2=0x999999&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;http://www.youtube.com/v/iXT2E9Ccc8A&amp;amp;hl=en&amp;amp;fs=1&amp;amp;rel=0&amp;amp;color1=0x3a3a3a&amp;amp;color2=0x999999&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;800&quot; height=&quot;630&quot;&gt;&lt;/embed&gt;&lt;/object&gt;
&lt;/p&gt;

</content>
   <updated>2009-07-10T00:00:00+01:00</updated>
   <category scheme="http://tomafro.net/tags/" term="salvador-dali" label="salvador-dali" />
   <category scheme="http://tomafro.net/tags/" term="whats-my-line" label="whats-my-line" />
   <category scheme="http://tomafro.net/tags/" term="tv" label="tv" />
   <category scheme="http://tomafro.net/tags/" term="youtube" label="youtube" />
 </entry>
 
 <entry>
   <id>http://tomafro.net</id>
   <link href="http://tomafro.net/2009/07/dscl-the-easy-way-to-add-hosts-on-osx"/>
   <title>dscl - the easy way to add hosts on OS X</title>
   <author>
     <name>Tom Ward</name>
     <email>tom@popdog.net</email>
   </author>
   <content type="html">&lt;p&gt;As a web developer, I often want several host names pointing at my local machine whilst developing and testing applications.  I may want to use Apache virtual hosts to serve multiple apps at once, or use subdomains to distinguish different accounts within a single application.&lt;/p&gt;

&lt;p&gt;Previously, to set these host names up, I would manually edit &lt;code&gt;/etc/hosts&lt;/code&gt;, adding entries like:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;127.0.0.1      twitter-killer.localhost
127.0.0.1      my-url-shortener-is-better-than-yours.localhost
127.0.0.1      yet-another-half-baked-idea.localhost
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This worked well on one level, but on another it just seemed wrong.  It's very manual, prone to error and pretty hard to script.  Recently though, thanks to a hint from Chris Parsons, I've found another way: using &lt;code&gt;dscl&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dscl&lt;/code&gt;, or Directory Service command line utility to give it its full name, has many uses.  For a web developer, the most relevant is probably the ability to add, list and create local directory entries under &lt;code&gt;/Local/Defaults/Hosts&lt;/code&gt; in the directory (not the file system).  These act like lines in &lt;code&gt;/etc/hosts&lt;/code&gt; but can be manipulated easily from the command line.&lt;/p&gt;

&lt;p&gt;To add an entry (easily the most interesting command) use:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;sudo dscl localhost -create /Local/Default/Hosts/twitter-killer.localhost IPAddress 127.0.0.1
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Once entries have been added, listing them is just as simple:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;sudo dscl localhost -list /Local/Default/Hosts IPAddress
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This produces a list in the form:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;twitter-killer.localhost                         127.0.0.1      
my-url-shortener-is-better-than-yours.localhost  127.0.0.1      
yet-another-half-baked-idea.localhost            127.0.0.1      
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Finally, you can remove entries with:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;sudo dscl localhost -delete /Local/Default/Hosts/twitter-killer.localhost
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Once you've mastered these commands, the possibilities are endless.  Here's a rake task to add all subdomains used in a project:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Application&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subdomains&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;all&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;collect&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subdomain&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:subdomains&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:add&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;Application&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subdomains&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subdomain&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;sb&quot;&gt;`sudo dscl localhost -create /Local/Default/Hosts/&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subdomain&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;.app.localhost IPAddress 127.0.0.1`&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  
  &lt;span class=&quot;n&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:remove&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;Application&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subdomains&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subdomain&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;sb&quot;&gt;`sudo dscl localhost -delete /Local/Default/Hosts/&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subdomain&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sb&quot;&gt;.app.localhost`&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Or if you're using &lt;a href=&quot;http://www.modrails.com/&quot;&gt;passenger&lt;/a&gt; for development, you can use a tool like &lt;a href=&quot;http://github.com/lazyatom/hostess/tree/master&quot;&gt;James Adam's hostess&lt;/a&gt; to automatically set up the host entry and virtual host entry for a site in one simple command.&lt;/p&gt;
</content>
   <updated>2009-07-08T00:00:00+01:00</updated>
   <category scheme="http://tomafro.net/tags/" term="osx" label="osx" />
   <category scheme="http://tomafro.net/tags/" term="dscl" label="dscl" />
   <category scheme="http://tomafro.net/tags/" term="development" label="development" />
   <category scheme="http://tomafro.net/tags/" term="shell" label="shell" />
   <category scheme="http://tomafro.net/tags/" term="reminder" label="reminder" />
 </entry>
 
 <entry>
   <id>http://tomafro.net</id>
   <link href="http://tomafro.net/2009/06/pimp-my-script-console"/>
   <title>Pimp my script/console</title>
   <author>
     <name>Tom Ward</name>
     <email>tom@popdog.net</email>
   </author>
   <content type="html">&lt;p&gt;For a long time I've had &lt;a href=&quot;http://github.com/tomafro/dotfiles/blob/master/dotfiles/irbrc&quot;&gt;an .irbrc file&lt;/a&gt; and a &lt;a href=&quot;http://github.com/tomafro/dotfiles/blob/master/dotfiles/railsrc&quot;&gt;.railsrc file&lt;/a&gt;, setting up some simple helpers methods in my &lt;code&gt;irb&lt;/code&gt; and &lt;code&gt;script/console&lt;/code&gt; sessions.  Today though, I wanted to add some more helpers specific to the project I'm working on.  Specifically, I wanted to be able to use my &lt;a href=&quot;http://github.com/notahat/machinist/tree/master&quot;&gt;machinist&lt;/a&gt; blueprints, to help me play around with some models.&lt;/p&gt;

&lt;p&gt;Adding &lt;a href=&quot;http://github.com/notahat/machinist/tree/master&quot;&gt;machinist&lt;/a&gt; isn't as simple as just requiring my blueprints though -- they require my ActiveRecord models, which aren't available when &lt;code&gt;.irbrc&lt;/code&gt; is loaded.  Luckily the solution is simple -- just add a couple of lines to the configuration in environment.rb:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;no&quot;&gt;Rails&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Initializer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;defined?&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;IRB&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;faker&amp;#39;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;notahat-machinist&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:lib&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;machinist&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:source&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;http://gems.github.com&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;IRB&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;conf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:IRB_RC&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Proc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;RAILS_ROOT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;config&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;console&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The key part is the line starting &lt;code&gt;IRB.conf[:IRB_RC]&lt;/code&gt;, which tells &lt;code&gt;irb&lt;/code&gt; to run the given when the session starts.  Luckily, this happens after rails has finished initializing.  I've set it to require &lt;code&gt;config/console.rb&lt;/code&gt;, to which I can add all sorts of configuration and helpers, knowing it will only get loaded in &lt;code&gt;script/console&lt;/code&gt; sessions where I want these shortcuts, not in my general code.  Here it is:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;expand_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;File&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;__FILE__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;/../spec/blueprints.rb&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;tomafro&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;Account&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find_by_login&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;tomafro&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;bbi&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;Client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find_by_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Big Bad Industries&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;



</content>
   <updated>2009-06-22T00:00:00+01:00</updated>
   <category scheme="http://tomafro.net/tags/" term="ruby" label="ruby" />
   <category scheme="http://tomafro.net/tags/" term="rails" label="rails" />
   <category scheme="http://tomafro.net/tags/" term="irb" label="irb" />
   <category scheme="http://tomafro.net/tags/" term="tip" label="tip" />
 </entry>
 
 <entry>
   <id>http://tomafro.net</id>
   <link href="http://tomafro.net/2009/05/read-active-record-columns-directly-from-the-class"/>
   <title>Read ActiveRecord columns directly from the class</title>
   <author>
     <name>Tom Ward</name>
     <email>tom@popdog.net</email>
   </author>
   <content type="html">&lt;p&gt;Sometimes you want to read just a single column from a collection of records, without the overhead of instantiating each and every one.  You could just execute raw SQL, but it's a shame to do away with the nice type conversion &lt;code&gt;ActiveRecord&lt;/code&gt; provides.  It'd also be a pity to get rid of find scoping, amongst other goodness.&lt;/p&gt;

&lt;p&gt;Enter &lt;code&gt;Tomafro::ColumnReader&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Tomafro::ColumnReader&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;column_reader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;column_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;options&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{})&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:as&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;column_name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pluralize&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;column&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;columns_hash&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;column_name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
    
    &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;module_eval&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;%{&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;      def self.&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;(options = {})&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;        merged = options.merge(:select =&amp;gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;column_name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;&amp;#39;)&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;        connection.select_all(construct_finder_sql(merged)).collect do |value| &lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;          v = value.values.first&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;          &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;column&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type_cast_code&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;v&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;        end&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;      end&lt;/span&gt;
&lt;span class=&quot;sx&quot;&gt;    }&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Once you've extended &lt;code&gt;ActiveRecord::Base&lt;/code&gt; with it, usage is simple.  In your models, declare which columns you want access to:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;extend&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Tomafro&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;ColumnReader&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Animal&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;column_reader&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;id&amp;#39;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;column_reader&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;  
 
  &lt;span class=&quot;n&quot;&gt;named_scope&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:dangerous&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:conditions&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:carnivorous&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; 
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Once you've done this, you can access values directly from the class, respecting scope, limits and other finder options.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;no&quot;&gt;Animal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;names&lt;/span&gt; 
&lt;span class=&quot;c1&quot;&gt;#=&amp;gt; [&amp;#39;Lion&amp;#39;, &amp;#39;Tiger&amp;#39;, &amp;#39;Zebra&amp;#39;, &amp;#39;Gazelle&amp;#39;]&lt;/span&gt;
 
&lt;span class=&quot;no&quot;&gt;Animal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;names&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:limit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; 
&lt;span class=&quot;c1&quot;&gt;#=&amp;gt; [&amp;#39;Lion&amp;#39;] (Normal finder options supported)&lt;/span&gt;
 
&lt;span class=&quot;no&quot;&gt;Animal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dangerous&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;names&lt;/span&gt; 
&lt;span class=&quot;c1&quot;&gt;#=&amp;gt; [&amp;#39;Lion&amp;#39;, &amp;#39;Tiger&amp;#39;] (Scoping respected)&lt;/span&gt;
 
&lt;span class=&quot;no&quot;&gt;Animal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ids&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#=&amp;gt; [1, 2, 3] (Values cast correctly)&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;



</content>
   <updated>2009-05-29T00:00:00+01:00</updated>
   <category scheme="http://tomafro.net/tags/" term="ruby" label="ruby" />
   <category scheme="http://tomafro.net/tags/" term="rails" label="rails" />
   <category scheme="http://tomafro.net/tags/" term="active-record" label="active-record" />
   <category scheme="http://tomafro.net/tags/" term="column-reader" label="column-reader" />
 </entry>
 
 <entry>
   <id>http://tomafro.net</id>
   <link href="http://tomafro.net/2009/05/an-objective-c-implementation-of-active-supports-inflector"/>
   <title>An Objective-C implementation of ActiveSupport's Inflector</title>
   <author>
     <name>Tom Ward</name>
     <email>tom@popdog.net</email>
   </author>
   <content type="html">&lt;p&gt;Over the last week I've been playing with Objective-C, for fun rather than profit.  Here's the first result of this dabbling - &lt;a href=&quot;http://github.com/tomafro/ActiveSupportInflector/tree/master&quot;&gt;an Objective-C implementation&lt;/a&gt; of ActiveSupport's pluralize and singularize methods.&lt;/p&gt;

&lt;p&gt;It's my first piece of code in the language, so I'd appreciate comments and feedback.&lt;/p&gt;
</content>
   <updated>2009-05-28T00:00:00+01:00</updated>
   <category scheme="http://tomafro.net/tags/" term="objective-c" label="objective-c" />
   <category scheme="http://tomafro.net/tags/" term="active-support" label="active-support" />
   <category scheme="http://tomafro.net/tags/" term="inflector" label="inflector" />
 </entry>
 
 <entry>
   <id>http://tomafro.net</id>
   <link href="http://tomafro.net/2009/05/i-thought-we-were-going-to-kew-gardens"/>
   <title>I thought we were going to Kew Gardens</title>
   <author>
     <name>Tom Ward</name>
     <email>tom@popdog.net</email>
   </author>
   <content type="html">&lt;p class=&quot;video&quot;&gt;
&lt;object width=&quot;800&quot; height=&quot;630&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/cRjJ1H11kYE&amp;amp;hl=en&amp;amp;fs=1&amp;amp;rel=0&amp;amp;color1=0x3a3a3a&amp;amp;color2=0x999999&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;http://www.youtube.com/v/cRjJ1H11kYE&amp;amp;hl=en&amp;amp;fs=1&amp;amp;rel=0&amp;amp;color1=0x3a3a3a&amp;amp;color2=0x999999&quot; type=&quot;application/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;800&quot; height=&quot;630&quot;&gt;&lt;/embed&gt;&lt;/object&gt;
&lt;/p&gt;

</content>
   <updated>2009-05-23T00:00:00+01:00</updated>
   <category scheme="http://tomafro.net/tags/" term="the-smiths" label="the-smiths" />
   <category scheme="http://tomafro.net/tags/" term="music" label="music" />
   <category scheme="http://tomafro.net/tags/" term="youtube" label="youtube" />
 </entry>
 
 <entry>
   <id>http://tomafro.net</id>
   <link href="http://tomafro.net/2009/05/using-rack-middleware-for-good-and-evil"/>
   <title>Using Rack Middleware for good and evil</title>
   <author>
     <name>Tom Ward</name>
     <email>tom@popdog.net</email>
   </author>
   <content type="html">&lt;p&gt;So we all know that &lt;a href=&quot;http://rack.rubyforge.org/&quot;&gt;Rack&lt;/a&gt; is awesome, and that we can use Rack::Middleware for all sorts of things: &lt;a href=&quot;http://github.com/brynary/rack-bug/tree/master&quot;&gt;debugging&lt;/a&gt;, &lt;a href=&quot;http://tomayko.com/src/rack-cache/&quot;&gt;caching&lt;/a&gt; and a &lt;a href=&quot;http://github.com/rack/rack-contrib/tree/master&quot;&gt;whole host more&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;What all these have in common (apart from maybe &lt;a href=&quot;http://github.com/rack/rack-contrib/blob/8b6323c8eecc8279088987c52b27dda5d4cadf7b/lib/rack/contrib/evil.rb&quot;&gt;Rack::Evil&lt;/a&gt;) is that they're all helpful.  They all make writing Rack applications easier.  Not my Middleware though.&lt;/p&gt;

&lt;h3&gt;Introducing Rack::Shuffler&lt;/h3&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Rack&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Shuffler&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;vi&quot;&gt;@app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;
      &lt;span class=&quot;vi&quot;&gt;@responses&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;vi&quot;&gt;@responses&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;vi&quot;&gt;@app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;vi&quot;&gt;@responses&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;rand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;vi&quot;&gt;@responses&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;ensure&lt;/span&gt;
      &lt;span class=&quot;vi&quot;&gt;@responses&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delete_at&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;rand&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;vi&quot;&gt;@responses&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;vi&quot;&gt;@responses&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;I suggest you add it to a colleague's app late on a Friday afternoon, and see how long it takes to drive them to insanity.&lt;/p&gt;
</content>
   <updated>2009-05-22T00:00:00+01:00</updated>
   <category scheme="http://tomafro.net/tags/" term="ruby" label="ruby" />
   <category scheme="http://tomafro.net/tags/" term="rack" label="rack" />
   <category scheme="http://tomafro.net/tags/" term="middleware" label="middleware" />
   <category scheme="http://tomafro.net/tags/" term="evil" label="evil" />
   <category scheme="http://tomafro.net/tags/" term="fun" label="fun" />
 </entry>
 
 <entry>
   <id>http://tomafro.net</id>
   <link href="http://tomafro.net/2009/05/imitation-is-the-sincerest-form-of-flattery"/>
   <title>If imitation is the sincerest form of flattery...</title>
   <author>
     <name>Tom Ward</name>
     <email>tom@popdog.net</email>
   </author>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://www.tiagoluchini.eu/&quot;&gt;...consider me flattered&lt;/a&gt;.&lt;/p&gt;
</content>
   <updated>2009-05-14T00:00:00+01:00</updated>
   <category scheme="http://tomafro.net/tags/" term="meta" label="meta" />
   <category scheme="http://tomafro.net/tags/" term="design" label="design" />
   <category scheme="http://tomafro.net/tags/" term="imitation" label="imitation" />
 </entry>
 
 <entry>
   <id>http://tomafro.net</id>
   <link href="http://tomafro.net/2009/05/automatching-rails-paths-in-cucumber"/>
   <title>Automatching rails paths in cucumber</title>
   <author>
     <name>Tom Ward</name>
     <email>tom@popdog.net</email>
   </author>
   <content type="html">&lt;p&gt;If you're using &lt;a href=&quot;http://cukes.info/&quot;&gt;cucumber&lt;/a&gt; as part of your testing, you probably have a &lt;code&gt;paths.rb&lt;/code&gt; file that looks something like this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;NavigationHelpers&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;path_to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;page_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;page_name&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt; /the home page/&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;root_path&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt; /the new client page/&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;new_client_path&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt; /the clients page/&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;clients_path&lt;/span&gt;    
    &lt;span class=&quot;c1&quot;&gt;# Add more page name =&amp;gt; path mappings here&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Can&amp;#39;t find mapping from &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;page_name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; to a path.&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
      &lt;span class=&quot;s2&quot;&gt;&amp;quot;Now, go and add a mapping in features/support/paths.rb&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;no&quot;&gt;World&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;NavigationHelpers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This let's us use nice descriptive names in our scenarios, but it starts to become a pain when we add more and more paths.  So how can we make it better?&lt;/p&gt;

&lt;p&gt;By automatically matching some rails paths.  Here's the code:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;NavigationHelpers&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;path_to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;page_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;page_name&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;when&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt; /the home page/&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;root_path&lt;/span&gt;   
    &lt;span class=&quot;c1&quot;&gt;# Add more page name =&amp;gt; path mappings here&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;match_rails_path_for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;page_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
        &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; 
        &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Can&amp;#39;t find mapping from &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;page_name&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; to a path.&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
        &lt;span class=&quot;s2&quot;&gt;&amp;quot;Now, go and add a mapping in features/support/paths.rb&amp;quot;&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;match_rails_path_for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;page_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;page_name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;match&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/the (.*) page/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;send&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;vg&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gsub&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot; &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;_&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;_path&amp;quot;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;no&quot;&gt;World&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;NavigationHelpers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;What it does is pretty simple.  Given a page name &lt;code&gt;the clients page&lt;/code&gt; (with no other matches defined) it will try and send &lt;code&gt;clients_path&lt;/code&gt;.  If successful, then it returns the result, otherwise nil.&lt;/p&gt;

&lt;p&gt;Not the biggest improvement in the world, but it's made my cucumber tests just a little bit easier to write.&lt;/p&gt;
</content>
   <updated>2009-05-13T00:00:00+01:00</updated>
   <category scheme="http://tomafro.net/tags/" term="cucumber" label="cucumber" />
   <category scheme="http://tomafro.net/tags/" term="rails" label="rails" />
   <category scheme="http://tomafro.net/tags/" term="ruby" label="ruby" />
   <category scheme="http://tomafro.net/tags/" term="testing" label="testing" />
   <category scheme="http://tomafro.net/tags/" term="tip" label="tip" />
 </entry>
 
 <entry>
   <id>http://tomafro.net</id>
   <link href="http://tomafro.net/2009/05/adam-sandersons-open-gem"/>
   <title>Adam Sanderson's open_gem</title>
   <author>
     <name>Tom Ward</name>
     <email>tom@popdog.net</email>
   </author>
   <content type="html">&lt;p&gt;The latest version of &lt;a href=&quot;http://rubygems.org/&quot;&gt;rubygems&lt;/a&gt; (1.3.2) now has an interface to add commands.  Making great use of this feature, &lt;a href=&quot;http://endofline.wordpress.com/&quot;&gt;Adam Sanderson&lt;/a&gt; has written &lt;a href=&quot;http://github.com/adamsanderson/open_gem&quot;&gt;open_gem&lt;/a&gt;, a simple but amazingly useful tool.&lt;/p&gt;

&lt;p&gt;You use it like this:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gem open activerecord
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This opens the activerecord gem in your favourite editor (taken from either &lt;code&gt;$GEM_OPEN_EDITOR&lt;/code&gt; or &lt;code&gt;$EDITOR&lt;/code&gt; environment variables).  If there are multiple versions of the gem installed, it will show a menu, letting you choose which version you require.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gem open activerecord
Open which gem?
 1. activerecord 2.1.0
 2. activerecord 2.3.2
&amp;gt; 
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;open_gem itself is a gem, and can be installed with:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gem install open_gem
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;To get it working, you need to have &lt;code&gt;$EDITOR&lt;/code&gt; set to something sensible:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;EDITOR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;mate
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;If you're running on OS X and use TextMate, you may have already set &lt;code&gt;$EDITOR&lt;/code&gt; to &lt;code&gt;mate -w&lt;/code&gt;, which let's you use TextMate as the editor for git commit messages and much more.  However, the &lt;code&gt;-w&lt;/code&gt; flag doesn't work with open_gem, so set the &lt;code&gt;$GEM_OPEN_EDITOR&lt;/code&gt; variable, and open_gem will use that instead:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;GEM_OPEN_EDITOR&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;mate
&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;You should now be good to go.  If you want to see how it works, just use it on itself!&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gem open open_gem
&lt;/pre&gt;
&lt;/div&gt;



</content>
   <updated>2009-05-06T00:00:00+01:00</updated>
   <category scheme="http://tomafro.net/tags/" term="ruby" label="ruby" />
   <category scheme="http://tomafro.net/tags/" term="gem" label="gem" />
   <category scheme="http://tomafro.net/tags/" term="tip" label="tip" />
   <category scheme="http://tomafro.net/tags/" term="gem-open" label="gem-open" />
 </entry>
 
</feed>
