<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Robby on Rails: Get to know a gem: Ghost</title>
    <link>http://www.robbyonrails.com/articles/2009/01/12/get-to-know-a-gem-ghost</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>thoughts.sort_by{|t| t[:topic]}.collect </description>
    <item>
      <title>Get to know a gem: Ghost</title>
      <description>&lt;p&gt;In my last post, &lt;a href="http://www.robbyonrails.com/articles/2009/01/11/subdomain-accounts-with-ruby-on-rails-explained"&gt;Subdomain accounts with Ruby on Rails explaind&lt;/a&gt;, I mentioned that you&amp;#8217;d need to modify your &lt;code&gt;/etc/hosts&lt;/code&gt; file to use custom subdomains for development/testing. Apparently, there is a much better way to handle this that I was introduced to by &lt;a href="http://www.atnan.com/"&gt;Nathan de Vries&lt;/a&gt;. Nathan suggests using a gem that I hadn&amp;#8217;t heard of before that bares the name of Ghost (&lt;a href="http://github.com/bjeanes/ghost/tree/master"&gt;view project on github&lt;/a&gt;).&lt;/p&gt;


	&lt;p&gt;Ghost describes itself as&amp;#8230;&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&amp;#8220;A gem that allows you to create, list, and modify local hostnames in 10.5 with ease…&amp;#8221;&amp;#8212;&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;If you&amp;#8217;ve ever had to modify your &lt;code&gt;/etc/hosts&lt;/code&gt; file for anything local, I highly encourage you to check out this shiny gem.&lt;/p&gt;


	&lt;h2&gt;Installing Ghost&lt;/h2&gt;


	&lt;p&gt;Like most gems, you can just install Ghost with the following command.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
~ : sudo gem install ghost
Password:
Successfully installed ghost-0.1.2-universal-darwin-9
1 gem installed
Installing ri documentation for ghost-0.1.2-universal-darwin-9...
Installing RDoc documentation for ghost-0.1.2-universal-darwin-9...
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Okay, now that Ghost is installed, let&amp;#8217;s see what we can do with it.&lt;/p&gt;


	&lt;h2&gt;Using Ghost for local domains/subdomains&lt;/h2&gt;


	&lt;p&gt;Ghost is fairly straight forward. It&amp;#8217;s essentially a friendly wrapper for &lt;a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/dscl.1.html"&gt;dscl&lt;/a&gt;, which is the Directory Service command line utility
for Mac &lt;span class="caps"&gt;OS X&lt;/span&gt;. I&amp;#8217;ve never played with that directly, but it seems that with Ghost&amp;#8230; I shouldn&amp;#8217;t need to. :-)&lt;/p&gt;


	&lt;p&gt;With Ghost, you can add, modify, and delete entries in the Directory Service by issuing any of the following commands. Let&amp;#8217;s start out by running &lt;code&gt;ghost&lt;/code&gt; to see what we have here.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
 ~ : ghost
USAGE: ghost add &amp;lt;hostname&amp;gt; [&amp;lt;ip=127.0.1.1&amp;gt;]
       ghost modify &amp;lt;hostname&amp;gt; &amp;lt;ip&amp;gt;
       ghost delete &amp;lt;hostname&amp;gt;
       ghost list
       ghost empty
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Okay, let&amp;#8217;s see if there is anything already listed.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
   ~ : ghost list
  Listing 0 host(s):
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Nope. Let&amp;#8217;s test this out. First, we&amp;#8217;ll try to ping a domain name that we hope doesn&amp;#8217;t exist.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
   ~ : ping bigbrown.cow
  ping: cannot resolve bigbrown.cow: Unknown host  
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Alright, now we&amp;#8217;ll add &lt;code&gt;bigbrown.cow&lt;/code&gt; with &lt;code&gt;ghost&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
   ~ : ghost add bigbrown.cow
  Password:
    [Adding] bigbrown.cow -&amp;gt; 127.0.0.1
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;As you can see, it required root credentials to do this as it&amp;#8217;s system-wide. Let&amp;#8217;s now see if we can talk to bigbrown.cow.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
   ~ : ping bigbrown.cow     
  PING bigbrown.cow (127.0.0.1): 56 data bytes
  64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.047 ms
  64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.035 ms
  ^C
  --- bigbrown.cow ping statistics ---
  2 packets transmitted, 2 packets received, 0% packet loss
  round-trip min/avg/max/stddev = 0.035/0.041/0.047/0.006 ms
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Excellent! If we run &lt;code&gt;ghost list&lt;/code&gt; again, we should see this record.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
~ : ghost list
Listing 1 host(s):
  bigbrown.cow -&amp;gt; 127.0.0.1
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;We can modify the record to a non-localhost IP as well with &lt;code&gt;ghost modify&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
   ~ : ghost modify bigbrown.cow 192.168.10.104
    [Modifying] bigbrown.cow -&amp;gt; 192.168.10.104
   ~ : ghost list
  Listing 1 host(s):
    bigbrown.cow -&amp;gt; 192.168.10.104  
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;I&amp;#8217;ll let you play with it yourself as there isn&amp;#8217;t much to it. This is a great little addition to my development environment. Thanks to Nathan for pointing it out and to &lt;a href="http://github.com/bjeanes"&gt;Bodaniel Jeanes&lt;/a&gt; for creating this useful gem.&lt;/p&gt;
</description>
      <pubDate>Mon, 12 Jan 2009 00:18:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:df6df9ad-a49c-4677-a44c-fe457e31cc36</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2009/01/12/get-to-know-a-gem-ghost</link>
      <category>Ruby on Rails</category>
      <category>Ruby</category>
      <category>Programming</category>
      <category>gem</category>
      <category>ghost</category>
      <category>dns</category>
      <category>development</category>
      <category>rubygems</category>
      <category>ruby</category>
    </item>
  </channel>
</rss>
