<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>rails symphonies</title>
	<link>http://rails.aizatto.com</link>
	<description>Ruby and Ruby on Rails Development</description>
	<pubDate>Wed, 16 Jan 2008 21:12:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
	<language>en</language>
			<item>
		<title>Logging DataMapper SQL Queries in Merb</title>
		<link>http://rails.aizatto.com/2008/01/17/logging-datamapper-sql-queries-in-merb/</link>
		<comments>http://rails.aizatto.com/2008/01/17/logging-datamapper-sql-queries-in-merb/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 21:06:49 +0000</pubDate>
		<dc:creator>aizatto</dc:creator>
		
		<category><![CDATA[DataMapper]]></category>

		<category><![CDATA[Merb]]></category>

		<guid isPermaLink="false">http://rails.aizatto.com/2008/01/17/logging-datamapper-sql-queries-on-merb/</guid>
		<description><![CDATA[I have been experimenting with Merb for a while as an alternative to Rails.
Compared to Rails, Merb is a lightweight framework.  By default Merb strips away a lot of unnecessary cruft, and in doing so does not include a default Object Relational Mapping (ORM), such as the popular ActiveRecord.  Though this doesn&#8217;t prevent [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>I have been experimenting with <a href="http://merbivore.org/">Merb</a> for a while as an alternative to Rails.</p>
<p>Compared to Rails, Merb is a lightweight framework.  By default Merb strips away a lot of unnecessary cruft, and in doing so does not include a default <a href="http://en.wikipedia.org/wiki/Object-relational_mapping">Object Relational Mapping</a> (ORM), such as the popular ActiveRecord.  Though this doesn&#8217;t prevent it from utilizing one, you are given the option of using a variety of frameworks to satisfy your application&#8217;s needs.  Presently Merb supports  ActiveRecord, <a href="http://datamapper.org/">DataMapper</a>, and <a href="http://code.google.com/p/ruby-sequel/">Sequel</a>.</p>
<p>Out of the three I decided to experiment with DataMapper, as I was already familiar with ActiveRecord, and wanted to explore something new.</p>
<p>When using the default settings, DataMapper doesn&#8217;t log the queries!  This makes it extremely difficult to debug an ORM especially when you are new to it.</p>
<h3>Enabling Logging</h3>
<p>Luckily you can add two keys <code>:log_stream</code> and <code>:log_level</code> to your <code>config/database.yml</code> to enable logging.</p>
<p><img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/>
<pre>:development: &amp;defaults
  :adapter: sqlite3
  :database: application_development
  :log_stream: STDOUT
  :log_level: 0</pre>
<p></p>
<h3>Disabling Logging</h3>
<p>Now When going into production mode, you should (if you desire) turn logging off.</p>
<p><img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/>
<pre>:production:
  &lt;&lt;: *defaults
  :database: application_production
  :log_stream: nil</pre>
<p></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://rails.aizatto.com/2008/01/17/logging-datamapper-sql-queries-in-merb/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Installing do_postgres on MacPorts</title>
		<link>http://rails.aizatto.com/2008/01/11/installing-do_postgres-on-macports/</link>
		<comments>http://rails.aizatto.com/2008/01/11/installing-do_postgres-on-macports/#comments</comments>
		<pubDate>Thu, 10 Jan 2008 19:39:00 +0000</pubDate>
		<dc:creator>aizatto</dc:creator>
		
		<category><![CDATA[MacPorts]]></category>

		<category><![CDATA[do_postgres]]></category>

		<guid isPermaLink="false">http://rails.aizatto.com/2008/01/11/installing-do_postgres-on-macports/</guid>
		<description><![CDATA[Ensure that pg_config is in your $PATH.
Note: This expects you are using PostgreSQL 8.2.  Alter the directories as required.
To test if pg_config is included, execute which pg_config :
Expected Result:
/opt/local/lib/postgresql82/bin/pg_config
Including pg_config into your $PATH
If you don&#8217;t get anything, then it isn&#8217;t in your path.  Append the following to your ~/.profile file:
export PATH=$PATH:/opt/local/lib/postgresql82/bin
Now it will [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Ensure that <code>pg_config</code> is in your <code>$PATH</code>.</p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Note:</b> This expects you are using PostgreSQL 8.2.  Alter the directories as required.</p>
<p>To test if <code>pg_config</code> is included, execute <code>which pg_config</code> <img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal" style="vertical-align: bottom;" />:</p>
<p><b>Expected Result:</b><br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>/opt/local/lib/postgresql82/bin/pg_config</code></p>
<h3>Including pg_config into your $PATH</h3>
<p>If you don&#8217;t get anything, then it isn&#8217;t in your path.  Append the following to your <code>~/.profile</code> file:<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>export PATH=$PATH:/opt/local/lib/postgresql82/bin</code></p>
<p>Now it will be included in all new terminal sessions.</p>
<h3>Installing do_postgres</h3>
<p>Now feel free to install the <code>do_postgres</code> gem.<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>sudo gem install do_postgres -- --with-pgsql-include-dir=/opt/local/include/postgresql82/ --with-pgsql-lib-dir=/opt/local/lib/postgresql82/</code></p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Note:</b> This is a single line command.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://rails.aizatto.com/2008/01/11/installing-do_postgres-on-macports/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Automatically Restart script/server For Easier Plugin Development with FSEvents</title>
		<link>http://rails.aizatto.com/2007/12/11/automatically-restart-scriptserver-for-easier-plugin-development-with-fsevents/</link>
		<comments>http://rails.aizatto.com/2007/12/11/automatically-restart-scriptserver-for-easier-plugin-development-with-fsevents/#comments</comments>
		<pubDate>Mon, 10 Dec 2007 18:53:36 +0000</pubDate>
		<dc:creator>aizatto</dc:creator>
		
		<category><![CDATA[FSEvents]]></category>

		<category><![CDATA[RubyCocoa]]></category>

		<guid isPermaLink="false">http://rails.aizatto.com/2007/12/11/automatically-restart-scriptserver-for-easier-plugin-development-with-fsevents/</guid>
		<description><![CDATA[When developing a Rails plugin, you are required to restart the server so that your plugin will be reloaded.  You&#8217;ll notice that after a while this becomes a rather tedious process, especially if you are working on a hot-off-the-press new plugin.
Following suit on my autotest with FSEvents, I opted to listen for any changes [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>When developing a Rails plugin, you are <strong>required to restart the server</strong> so that your plugin will be reloaded.  You&#8217;ll notice that after a while this becomes a rather tedious process, especially if you are working on a hot-off-the-press new plugin.</p>
<p>Following suit on my <a href="http://rails.aizatto.com/2007/11/28/taming-the-autotest-beast-with-fsevents/">autotest with FSEvents</a>, I opted to listen for any changes to the <code>vendor/plugins</code> and <code>lib</code> directories to restart the server as required.  Thus freeing me of the <em>horrible grunt work</em> of restarting the server.</p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Note:</b> This is Mac OS X 10.5 Leopard specific.</p>
<h3>The Incantation</h3>
<p>Create the required file <code>script/autorestart_server</code>, and put this beauty in it.</p>
<p>For an easy to copy dump, click &#8220;<code>view plain</code>&#8220;.</p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Note:</b> Don&#8217;t forget to make it executable! <code>chmod u+x script/autorestart_server</code> <img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal" style="vertical-align: bottom;" /></p>
<pre><code>#!/usr/bin/env ruby

PATHS_TO_OBSERVE = /^(lib|vendor\/plugins)/

require 'osx/foundation'
OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
include OSX

def start_server
  IO.popen("script/server #{ARGV.join(' ')}")
end

def stop_server(io)
  return if io.nil?
  Process.kill("INT", io.pid)  
end

io = start_server

callback = proc do |stream, ctx, numEvents, paths, marks, eventIDs|
  paths.regard_as('*')
  rpaths = []
  length = Dir.pwd.length + 1

  numEvents.times { |i| rpaths &lt;&lt; paths[i][length..-1] }

  next if rpaths.select { |path| path =~ PATHS_TO_OBSERVE }.empty?
  stop_server(io)
  puts "Restarting server"
  io = start_server
end

stream = FSEventStreamCreate(KCFAllocatorDefault, callback, nil, [Dir.pwd], KFSEventStreamEventIdSinceNow, 1.0, 0)
unless stream
  puts "Failed to create stream"
  exit
end

FSEventStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), KCFRunLoopDefaultMode)
unless FSEventStreamStart(stream)
  puts "Failed to start stream"
  exit 
end

begin
  CFRunLoopRun()
rescue Interrupt
  stop_server(io)
  FSEventStreamStop(stream)
  FSEventStreamInvalidate(stream)
  FSEventStreamRelease(stream)
end</code></pre>
<h3>Automatically Restarting script/server</h3>
<p>Now feel free to execute <code>script/autorestart_server</code> <img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal" style="vertical-align: bottom;" /></p>
<p>Wondering where else I can inject FSEvents into, its quite a handy little tool&#8230;</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://rails.aizatto.com/2007/12/11/automatically-restart-scriptserver-for-easier-plugin-development-with-fsevents/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Taming the autotest Beast with FSEvents</title>
		<link>http://rails.aizatto.com/2007/11/28/taming-the-autotest-beast-with-fsevents/</link>
		<comments>http://rails.aizatto.com/2007/11/28/taming-the-autotest-beast-with-fsevents/#comments</comments>
		<pubDate>Tue, 27 Nov 2007 18:12:07 +0000</pubDate>
		<dc:creator>aizatto</dc:creator>
		
		<category><![CDATA[FSEvents]]></category>

		<category><![CDATA[RubyCocoa]]></category>

		<category><![CDATA[autotest]]></category>

		<guid isPermaLink="false">http://rails.aizatto.com/2007/11/28/towards-a-saner-autotest-with-fsevents/</guid>
		<description><![CDATA[autotest is a great tool and all, but it is simply resource intensive.  Due to autotest&#8217;s implementation, it eats up CPU resources, not because the tests are always running (only after you modify your file), but because autotest continually polls each file in your directory, and sub directories, and checks to see if it [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p><code>autotest</code> is a great tool and all, but it is simply resource intensive.  Due to <code>autotest</code>&#8217;s implementation, it eats up CPU resources, not because the tests are always running (only after you modify your file), but because <code>autotest</code> continually polls each file in your directory, and sub directories, and checks to see if it has been modified.</p>
<p>This continual polling isn&#8217;t good for CPU resources.  Now I may have some spare cycles to let <code>autotest</code> do its thang, but it also doesn&#8217;t sound too healthy for my hard drive.</p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Note:</b> This is Mac OS X 10.5 Leopard specific. </p>
<h3>Along Comes a Leopard</h3>
<p>Whilst reading the <a href="http://arstechnica.com/reviews/os/mac-os-x-10-5.ars/">Arstechnica review on Leopard</a>, I came upon the <a href="http://arstechnica.com/reviews/os/mac-os-x-10-5.ars/7">section on the  File System Events</a> (FSEvents) that was introduced in 10.4 actually (for Spotlight), but used once again for Time Machine.  In Mac OS X 10.5 Leopard, the API was opened up for the public to consume.</p>
<h3>File System Events (FSEvents)</h3>
<p>In its simplest level, your application will notify FSEvents, that it wants to listen to a particular directory, and when that directory (or its sub directories) are modified, FSEvents basically triggers a callback in your application.  This allows you to hook to, listen to file system changes, and react to accordingly.</p>
<p>This is exactly what I needed to calm the fury of the <code>autotest</code> beast.</p>
<h3>Install RubyCocoa</h3>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Update:</b> It looks like the code works on the stock Ruby and RubyCocoa out of the box actually.  You don&#8217;t need to install the latest version.<br />
First of all, you need to install <a href="http://www.rubycocoa.com/">RubyCocoa</a>, as this provides us with the bindings required to communicate with FSEvents.  As I installed Ruby via MacPorts, I opted to do a source install (the MacPorts at present, is one version behind).  <a href="http://rails.aizatto.com/2007/11/26/building-rubycocoa-with-ruby-macports-installation/">I did run into trouble, encountering this error &#8220;<strong>file is not of required architecture</strong>&#8220;.</a></p>
<p>If you ever needed a reason to actually use RubyCocoa, let this be your reason!</p>
<h3>Taming the beast</h3>
<p>Once installed, dump this little gem into your <code>~/.autotest</code> file:</p>
<p>For an easy to copy dump, click &#8220;<code>view plain</code>&#8220;.</p>
<pre><code>class Autotest
  def run
    hook :run
    reset

    run_tests

    require 'osx/foundation'
    OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'

    callback = proc do |stream, ctx, numEvents, paths, marks, eventIDs|
      paths.regard_as('*')
      rpaths = []

      numEvents.times { |i| rpaths &lt;&lt; paths[i] }

      run_tests_in_paths(*rpaths)
    end

    allocator = OSX::KCFAllocatorDefault
    context   = nil
    path      = [Dir.pwd]
    sinceWhen = OSX::KFSEventStreamEventIdSinceNow
    latency   = 1.0
    flags     = 0

    stream   = OSX::FSEventStreamCreate(allocator, callback, context, path, sinceWhen, latency, flags)
    unless stream
      puts "Failed to create stream"
      exit
    end

    OSX::FSEventStreamScheduleWithRunLoop(stream, OSX::CFRunLoopGetCurrent(), OSX::KCFRunLoopDefaultMode)
    unless OSX::FSEventStreamStart(stream)
      puts "Failed to start stream"
      exit 
    end

    OSX::CFRunLoopRun()
  rescue Interrupt
    OSX::FSEventStreamStop(stream)
    OSX::FSEventStreamInvalidate(stream)
    OSX::FSEventStreamRelease(stream)
  end

  def find_files_in_paths(*paths)
    current_dir = Dir.pwd.length + 1
    result = {}
    paths.each do |path|
      # Largely copied from autotest
      Find.find path do |f|
        Find.prune if @exceptions and f =~ @exceptions and test ?d, f
        next if test ?d, f
        next if f =~ /(swp|~|rej|orig)$/
        next if f =~ /\/\.?#/

        filename = f[current_dir..-1]
        result[filename] = File.stat(filename).mtime rescue next
      end
    end
    return result
  end

  def run_tests_in_paths(*paths)
    find_files_to_test(find_files_in_paths(*paths))
    return if @files_to_test.empty?
    # Copied from autotest
    cmd = make_test_cmd @files_to_test

    hook :run_command
    puts cmd

    old_sync = $stdout.sync
    $stdout.sync = true
    @results = []
    line = []
    begin
      open("| #{cmd}", "r") do |f|
        until f.eof? do
          c = f.getc
          putc c
          line &lt;&lt; c
          if c == ?\n then
            @results &lt;&lt; line.pack("c*")
            line.clear
          end
        end
      end
    ensure
      $stdout.sync = old_sync
    end
    hook :ran_command
    @results = @results.join

    handle_results(@results)
  end
end</code></pre>
<p>Now when you run <code>autotest</code>, you&#8217;ll run into something like this:<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/>
<pre>/Users/aizat/.autotest:4: warning: method redefined; discarding old run</pre>
<p></p>
<p>Don&#8217;t worry about it, and feel free to ignore it.</p>
<p>With this code, you can also tame the beast.  There you have it, a <strong>much saner autotest</strong>, only for Mac OS X 10.5 Leopard.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://rails.aizatto.com/2007/11/28/taming-the-autotest-beast-with-fsevents/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Building RubyCocoa with Ruby MacPorts Installation</title>
		<link>http://rails.aizatto.com/2007/11/26/building-rubycocoa-with-ruby-macports-installation/</link>
		<comments>http://rails.aizatto.com/2007/11/26/building-rubycocoa-with-ruby-macports-installation/#comments</comments>
		<pubDate>Mon, 26 Nov 2007 14:32:33 +0000</pubDate>
		<dc:creator>aizatto</dc:creator>
		
		<category><![CDATA[RubyCocoa]]></category>

		<guid isPermaLink="false">http://rails.aizatto.com/2007/11/26/building-rubycocoa-with-macports-installation/</guid>
		<description><![CDATA[First I tried installing RubyCocoa via MacPorts, but that failed.  Unbothered, I went straight to the RubyCocoa page, and noticed it was running a newer version, v0.13.
So I happily downloaded the tar ball, and followed their installation guide, but ran into a little problem: 
/Developer/usr/bin/gcc-4.0 -o /Users/aizat/Downloads/RubyCocoa-0.13.0/framework/build/Default/RubyCocoa.framework/Versions/A/RubyCocoa -L/Users/aizat/Downloads/RubyCocoa-0.13.0/framework/build/Default -L/opt/local/lib -F/Users/aizat/Downloads/RubyCocoa-0.13.0/framework/build/Default -filelist /Users/aizat/Downloads/RubyCocoa-0.13.0/framework/build/RubyCocoa.build/Default/RubyCocoa.build/Objects-normal/i386/RubyCocoa.LinkFileList -framework Foundation [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>First I tried installing RubyCocoa via MacPorts, but that failed.  Unbothered, I went straight to the RubyCocoa page, and noticed it was running a newer version, v0.13.</p>
<p>So I happily downloaded the tar ball, and <a href="http://rubycocoa.sourceforge.net/GettingStarted">followed their installation guide</a>, but ran into a little problem: </p>
<p><img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>/Developer/usr/bin/gcc-4.0 -o /Users/aizat/Downloads/RubyCocoa-0.13.0/framework/build/Default/RubyCocoa.framework/Versions/A/RubyCocoa -L/Users/aizat/Downloads/RubyCocoa-0.13.0/framework/build/Default -L/opt/local/lib -F/Users/aizat/Downloads/RubyCocoa-0.13.0/framework/build/Default -filelist /Users/aizat/Downloads/RubyCocoa-0.13.0/framework/build/RubyCocoa.build/Default/RubyCocoa.build/Objects-normal/i386/RubyCocoa.LinkFileList -framework Foundation -arch i386 -Wl,-single_module -compatibility_version 1 -current_version 1 -install_name @executable_path/../Frameworks/RubyCocoa.framework/Versions/A/RubyCocoa -dynamiclib -mmacosx-version-min=10.5 -undefined suppress -flat_namespace -arch ppc -arch i386 -arch ppc64 -arch x86_64 -lxml2 -lffi /opt/local/lib/libruby.1.8.6.dylib<br />
ld: warning in /opt/local/lib/libxml2.dylib, file is not of required architecture<br />
ld: warning in /opt/local/lib/libruby.1.8.6.dylib, file is not of required architecture<br />
ld: in /opt/local/lib/libxml2.2.dylib, file is not of required architecture<br />
collect2: ld returned 1 exit status<br />
ld: warning in /opt/local/lib/libxml2.dylib, file is not of required architecture<br />
ld: warning in /opt/local/lib/libruby.1.8.6.dylib, file is not of required architecture<br />
ld: in /opt/local/lib/libxml2.2.dylib, file is not of required architecture<br />
collect2: ld returned 1 exit status<br />
ld: warning in /opt/local/lib/libxml2.dylib, file is not of required architecture<br />
ld: warning in /opt/local/lib/libruby.1.8.6.dylib, file is not of required architecture<br />
ld: in /opt/local/lib/libxml2.2.dylib, file is not of required architecture<br />
collect2: ld returned 1 exit status<br />
ld: warning, duplicate dylib /opt/local/lib/libxml2.2.dylib<br />
lipo: can't open input file: /var/folders/Pz/Pz+BnoKJHVOVErgN6VsRJk+++TI/-Tmp-//cc7uvHOl.out (No such file or directory)<br />
** BUILD FAILED **<br />
setup failed<br />
'system /usr/bin/xcodebuild' failed</code></p>
<p>&#8220;<strong>file is not of required architecture</strong>&#8220;, what in the world?</p>
<p>Well no worries, I was still able to get pass it, just turn on the &#8211;build-universal=no flag when you configure.</p>
<p><img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/>
<pre>ruby install.rb config --build-universal=no
ruby install.rb setup
sudo ruby install.rb install</pre>
<p></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://rails.aizatto.com/2007/11/26/building-rubycocoa-with-ruby-macports-installation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>autotest-ting your Rails Application with Visual and Audio Feedback using Growl and mpg321</title>
		<link>http://rails.aizatto.com/2007/11/19/autotest-ting-your-rails-application-with-visual-and-audio-feedback-using-growl-and-mpg321/</link>
		<comments>http://rails.aizatto.com/2007/11/19/autotest-ting-your-rails-application-with-visual-and-audio-feedback-using-growl-and-mpg321/#comments</comments>
		<pubDate>Sun, 18 Nov 2007 17:46:30 +0000</pubDate>
		<dc:creator>aizatto</dc:creator>
		
		<category><![CDATA[Mac OS X]]></category>

		<category><![CDATA[RSpec]]></category>

		<category><![CDATA[autotest]]></category>

		<guid isPermaLink="false">http://rails.aizatto.com/2007/11/19/autotest-ting-your-rails-application-with-visual-and-audio-feedback-with-growl-and-mpg321/</guid>
		<description><![CDATA[autotest is a commandline tool that comes packaged together with ZenTest.  Designed to continually test your Rails application, autotest makes a slight notch easier by removing the need to repeatedly call the rake task to run your application&#8217;s various tests.
Note: autotest is not limited to the default Ruby Test::Unit::TestCase.  It will even work [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p><a href="http://www.zenspider.com/ZSS/Products/ZenTest/#rsn">autotest</a> is a commandline tool that comes packaged together with <a href="http://www.zenspider.com/ZSS/Products/ZenTest/">ZenTest</a>.  Designed to continually test your Rails application, <code>autotest</code> makes a slight notch easier by removing the need to repeatedly call the rake task to run your application&#8217;s various tests.</p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Note:</b> autotest is not limited to the default Ruby <code>Test::Unit::TestCase</code>.  It will even work out of the box with <a href="http://rspec.rubyforge.org">RSpec</a>.   </p>
<h3>Installing autotest</h3>
<p><code>autotest</code> is actually in the ZenTest gem.<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>sudo gem install -y ZenTest</code></p>
<p>Go to your application root directory and run <code>autotest</code> and watch it go!<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>autotest</code></p>
<p>Dead simple right? But still slightly irritating having to switch back to the terminal to see the results of test.  So lets spruce it up a little, lets make it notify us of the results.</p>
<h3>Visual Feedback with Growl</h3>
<p><a href="http://www.growl.info">Growl</a> is a notification that is over layed on top of your desktop, so that other applications are able to notify/inform you of anything, generally updates.  For example <a href="http://www.adiumx.com/">Adium</a> uses it to notify you of people logging in or out.</p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Note:</b> Growl is a Mac OS X application.  For other platforms you&#8217;ll have to look at integration with their notification apps, for example<code>knotify</code>, or <code>gnome-notification</code>.</p>
<p>Combined together with Growl, you will continuously be notified of the current status of your test suite through a nice non disruptive interface.  Thus helping to ensure the integrity of your code base.</p>
<h4>Installing Growl</h4>
<p><a href="http://growl.info/downloads.php">Download Growl</a> and install it.  But <strong>don&#8217;t eject</strong> the Disc Image yet.  We have to install the <code>growlnotify</code> command as well.  This has to be done via the command line, so pull up your Terminal again.</p>
<p>We need to find out where Growl has been mounted to.<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>mount | grep -i growl</code></p>
<p><strong>Possible Result:</strong><br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>/dev/disk2s2 on /Volumes/Growl 1.1.2 (local, nodev, nosuid, read-only, mounted by aizat)</code></p>
<p>From here you can see it has been mounted on <code>/Volumes/Growl 1.1.2</code>.  Now go back to your Terminal, and we&#8217;ll install <code>growlnotify</code>.</p>
<p><img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>cd "/Volumes/Growl 1.1.2/"<br />
cd Extras/growlnotify<br />
sudo ./install.sh</code></p>
<p>By default <code>growlnotify</code> is installed into <code>/usr/local/bin</code>, your applications may  not be able to see that this exists. So let&#8217;s find out.</p>
<p><strong>Execute:</strong><br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>which growlnotify</code></p>
<p><strong>Desired Result:</strong><br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>/usr/local/bin/growlnotify</code></p>
<p><strong>Possible Result:</strong><br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>no growlnotify in /opt/local/bin /opt/local/sbin /usr/local/bin /bin /sbin /usr/bin /usr/sbin</code></p>
<p>We want the desired result, so what do you do if you don&#8217;t get it?<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>echo "export PATH=/usr/local/bin:$PATH" &gt;&gt; ~/.bashrc</code></p>
<p>Now <code>growlnotify</code> is accessible by all new Terminal sessions.</p>
<p>Let&#8217;s give it a shot, and test out Growl!<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>growlnotify -m "Hey <a href="http://en.wikipedia.org/wiki/Tony_the_Tiger">Tony</a>, isn&#8217;t this just grrrrrrreat?&#8221;</code></p>
<h4>Integrating Growl with autotest</h4>
<p>We need to create a <code>.autotest</code> (yes with the period) file in your home directory.<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>touch ~/.autotest<br />
open ~/.autotest</code> </p>
<p>Now stuff this in there!</p>
<pre><code>module Autotest::Growl
  
  def self.growl title, msg, img, pri=0, sticky=""
    system "growlnotify -n autotest --image #{img.inspect} -p #{pri} -m #{msg.inspect} #{title} #{sticky}"
  end

  Autotest.add_hook :ran_command do |at|
    results = [at.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/)
    if output
      if $~[2].to_i &gt; 0
        growl "Test Results", "#{output}", File.join(ENV['HOME'], %w[Library Application\ Support autotest rails_fail.png]), 2
      else
        growl "Test Results", "#{output}", File.join(ENV['HOME'], %w[Library Application\ Support autotest rails_ok.png])
      end
    end
  end
    
end</code></pre>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><strong>Note:</strong> <a href="http://wincent.com/knowledge-base/Setting_up_autotest_to_use_Growl">Adapted from Wincent Knowledge Base</a>. I also took the personal liability to move files to the ~/Library/Application Support/ directory as I thought it would be more appropriate.  Your choice, just change as desired.</p>
<p>Now for the final touch, the elusive images!<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>mkdir -p ~/Library/Application\ Support/autotest<br />
cd ~/Library/Application\ Support/autotest<br />
curl -O http://blog.internautdesign.com/files/rails_fail.png<br />
curl -O http://blog.internautdesign.com/files/rails_ok.png<br />
</code></p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Note:</b> If you want, you can even change the images to whatever you want yourself, just change lines 12 and 14 to point to the image location.</p>
<h4>autotest-ing</h4>
<p>Now go to the root directory of your Rails application, and simply execute:<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>autotest</code></p>
<p>and you should soon be notified of the results of your test.</p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Note:</b> You can further customize Growl in the System Preferences!</p>
<h3>Audio Feedback</h3>
<p>Visual feedback is cool, but it would be even more awesome if it had audio feedback to accompany it.</p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Note:</b> This method is cross platform.</p>
<p>This was first described on <a href="http://fozworks.com/2007/7/28/autotest-sound-effects">FozWorks (read on how to Install)</a></p>
<p>As I aggregated my <code>autotest</code> images into the <code>~/Library/Application Support/autotest</code> directory, I thought I&#8217;d dump the sound files in there as well.  Just pay attention when you have to modify your <code>~/.autotest</code> to accommodate the different path.</p>
<p>The only disappointment with the default sounds they provide is that, they are a little bit soft, and is often drowned out by my music player.  But no worries, you can decide to use your own effects, or if your like me, increase the gain with <a href="http://audacity.sourceforge.net/">Audacity</a>.</p>
<p>In the mean time, anyone have some interesting replacement sound effects?</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://rails.aizatto.com/2007/11/19/autotest-ting-your-rails-application-with-visual-and-audio-feedback-using-growl-and-mpg321/feed/</wfw:commentRss>
		</item>
		<item>
		<title>autotest-ing your Rails Plugin</title>
		<link>http://rails.aizatto.com/2007/11/19/autotest-ing-your-rails-plugin/</link>
		<comments>http://rails.aizatto.com/2007/11/19/autotest-ing-your-rails-plugin/#comments</comments>
		<pubDate>Sun, 18 Nov 2007 16:27:15 +0000</pubDate>
		<dc:creator>aizatto</dc:creator>
		
		<category><![CDATA[Rails Plugin Development]]></category>

		<category><![CDATA[autotest]]></category>

		<guid isPermaLink="false">http://rails.aizatto.com/2007/11/19/autotest-ing-your-rails-plugin/</guid>
		<description><![CDATA[autotest is a great tool to easily test your Rails application. autotest runs in the background and continuously test your app, and notify you of the results, thus leaving you to build your app with the confidence of knowing that it isn&#8217;t going to break without your knowledge, and as soon as possible.  It [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p><code>autotest</code> is a great tool to easily test your Rails application. <code>autotest</code> runs in the background and continuously test your app, and notify you of the results, thus leaving you to build your app with the confidence of knowing that it isn&#8217;t going to break without your knowledge, and as soon as possible.  It makes writing your tests easier, and the easier it is, the more likely you&#8217;ll end up doing it.</p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><strong>Note:</strong> I have only used autotest with <a href="http://rspec.rubyforge.org">RSpec</a>, and all details are based on that.  I also assume that your plugin is installed in <code>vendor/plugins</code> </p>
<p>I have been working on a plugin that uses <a href="http://rspec.rubyforge.org">RSpec</a> to help me test the plugin&#8217;s integrity.  After a while I got a little tired of continuously running a <code>rake</code> task to test it out.</p>
<p>Sadly <strong>by default, autotest doesn&#8217;t test your plugin directory</strong>.  What a shame, but it also provides a challenge!</p>
<h3>Enabling autotest on your Rails plugin</h3>
<p>Now go into your plugin directory and create a folder called <code>autotest</code>.<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>cd vendor/plugins/secret_sauce/<br />
mkdir autotest</code></p>
<p>Inside the <code>autotest</code> directory, create a file called <code>discover.rb</code> and dump this little gem inside:</p>
<pre><code>$:.push(File.join(File.dirname(__FILE__), %w[.. .. rspec]))

Autotest.add_discovery do
  "rspec"
end</code></pre>
<p>While your in the root directory of your plugin, in my case its <code>secret_sauce</code>, just run <code>autotest</code>.<br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>autotest</code></p>
<p>Boom! You are now <strong><code>autotest</code>-ing your Rails plugin</strong>!  Sweet.</p>
<h3>Using your Application&#8217;s RSpec Options</h3>
<p>You&#8217;ll notice that your <code>autotest</code>s lack a bit of color&#8230; Or perhaps you want it to run the same options as your application.  Have no worry soldier!  First go to your <code>spec</code> directory in your plugin, and create a symbolic link back to the original <code>spec.opts</code> file.</p>
<p><strong>Using your application&#8217;s RSpec options:</strong><br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>cd vendor/plugins/secret_sauce/spec<br />
ln -s ../../../../spec/spec.opts</code></p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><strong>Note:</strong> This only works for Unix-like operating systems, thats Mac OS X, Linux, and FreeBSD to name a few.  For you Windows folks, you will have to just create a <code>spec.opts </code>file, or <strong>change your OS</strong>. </p>
<p>If you want to run under another set of options, just create a <code>spec.opts</code> file in the <code>spec</code> directory of your plugin, and fill in the details.</p>
<h3>One shortcoming</h3>
<p>Sure one shortcoming is that it&#8217;s not integrated when calling <code>autotest</code> in your application root directory, but something is always better than nothing.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://rails.aizatto.com/2007/11/19/autotest-ing-your-rails-plugin/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Creating File Paths the Easy Way</title>
		<link>http://rails.aizatto.com/2007/11/17/creating-file-paths-the-easy-way/</link>
		<comments>http://rails.aizatto.com/2007/11/17/creating-file-paths-the-easy-way/#comments</comments>
		<pubDate>Sat, 17 Nov 2007 12:02:02 +0000</pubDate>
		<dc:creator>aizatto</dc:creator>
		
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://rails.aizatto.com/2007/11/17/creating-file-paths-the-easy-way/</guid>
		<description><![CDATA[The Traditional Way
The traditional way to create file paths that are cross platform in Ruby, was to join them up as arguments in a File.join call:
File.join(File.dirname(__FILE__), '..', '..', 'config', 'database.yml))
Result:
"./../../config/database.yml"
Now thats all nice and everything but if you want to change it, you would have the inconvenience of having to add or remove commas, or [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><h3>The Traditional Way</h3>
<p>The traditional way to create file paths that are cross platform in Ruby, was to join them up as arguments in a <code>File.join</code> call:</p>
<pre><code>File.join(File.dirname(__FILE__), '..', '..', 'config', 'database.yml))</code></pre>
<p><strong>Result:</strong><br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>"./../../config/database.yml"</code></p>
<p>Now thats all nice and everything but <strong>if you want to change it</strong>, you would have the inconvenience of having to add or remove commas, or single|double quotes, which can be a bit of <strong>a hassle</strong>.</p>
<h3>Prettying it Up</h3>
<p>So how about we pretty it up a little?</p>
<pre><code>File.join(File.dirname(__FILE__), %w[.. .. config database.yml]))</code></pre>
<p><strong>Result:</strong><br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>"./../../config/database.yml"</code></p>
<p>Now doesn&#8217;t that look <strong>a whole better</strong>?</p>
<h3>What in the world is <code>%w[...]</code>?</h3>
<p>Why does this work just as well?</p>
<p>The <code>%w[...]</code> creates an array of <code>String</code>s separated by the whitespaces in the list.</p>
<pre><code>%w[.. .. config database.yml]</code></pre>
<p><strong>Result:</strong><br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>["..", "..", "config",  "database.yml"]</code></p>
<p>But what if you have a space in the file name?  Well you can use a <code>backslash</code> as an escape key and presto!</p>
<pre><code>%w[.. .. config a\ file]</code></pre>
<p><strong>Result:</strong><br />
<img src="http://static.aizatto.com/tango/16x16/apps/utilities-terminal.png" alt="Terminal"/><code>["..", "..", "config",  "a file"]</code></p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Note:</b> I&#8217;m not so sure what this operator is called, and any help giving it a name would be greatly appreciated.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://rails.aizatto.com/2007/11/17/creating-file-paths-the-easy-way/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Malaysia.rb August 2007 Meetup</title>
		<link>http://rails.aizatto.com/2007/08/16/malaysiarb-august-2007-meetup/</link>
		<comments>http://rails.aizatto.com/2007/08/16/malaysiarb-august-2007-meetup/#comments</comments>
		<pubDate>Thu, 16 Aug 2007 14:37:04 +0000</pubDate>
		<dc:creator>aizatto</dc:creator>
		
		<category><![CDATA[Malaysia Ruby Brigade]]></category>

		<guid isPermaLink="false">http://rails.aizatto.com/2007/08/16/malaysiarb-august-2007-meetup/</guid>
		<description><![CDATA[Date:  Thursday, August 23, 2007
Time: 8:00pm - 10:00pm
Location: Starbucks
Street: Ikea Cafeteria
City/Town: Ikea, Ikano Power Center
For you facebook guys:
http://monashedu.facebook.com/event.php?eid=4695826745
]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Date:  Thursday, August 23, 2007<br />
Time: 8:00pm - 10:00pm<br />
Location: Starbucks<br />
Street: Ikea Cafeteria<br />
City/Town: Ikea, Ikano Power Center</p>
<p>For you facebook guys:<br />
<a href="http://monashedu.facebook.com/event.php?eid=4695826745">http://monashedu.facebook.com/event.php?eid=4695826745</a></p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://rails.aizatto.com/2007/08/16/malaysiarb-august-2007-meetup/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Remove Firebug JavaScript Console Calls on Deployment</title>
		<link>http://rails.aizatto.com/2007/07/29/remove-firebug-javascript-console-calls-on-deployment/</link>
		<comments>http://rails.aizatto.com/2007/07/29/remove-firebug-javascript-console-calls-on-deployment/#comments</comments>
		<pubDate>Sun, 29 Jul 2007 12:58:22 +0000</pubDate>
		<dc:creator>aizatto</dc:creator>
		
		<category><![CDATA[Capistrano]]></category>

		<category><![CDATA[Firebug]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Rails Deployment]]></category>

		<guid isPermaLink="false">http://rails.aizatto.com/2007/07/29/remove-firebug-javascript-console-calls-on-deployment/</guid>
		<description><![CDATA[One thing I keep forgetting to do when deploying a Rails application is to remove any Firebug JavaScript console calls I use for debugging.
You know, those:
console.log("Please execute");
console.info("Warning " + collections.length + " Areas found")
Or something like that.
When committing back to the repository, you simply forget to remove them.  Thus when deploying your new code, [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>One thing I keep forgetting to do when deploying a Rails application is to remove any <a href="http://getfirebug.com/logging.html">Firebug JavaScript console calls</a> I use for debugging.</p>
<p>You know, those:</p>
<pre><code>console.log("Please execute");
console.info("Warning " + collections.length + " Areas found")</code></pre>
<p>Or something like that.</p>
<p>When committing back to the repository, you simply forget to remove them.  Thus when deploying your new code, for those people who don&#8217;t have Firebug installed, the <em>script will end in a premature death</em>.</p>
<p><b>Oh noes!</b></p>
<p>This definitely isn&#8217;t cool, and its just a <em>minor thing</em> you forgot to do&#8230;and its causing a hell lot of problems.</p>
<p>Lucky for us we can hook into the Capistrano <code>after update code</code> callback to comment/strip out those lines from the JavaScript file.</p>
<p><b>To Comment Out:</b></p>
<pre><code>
task :after_update_code, :roles =&gt; :app do
  javascript_path = File.join(release_path, 'public', 'javascripts', '*.js')
  run "sed -i -r 's/(\\/\\/|^)(\\s*console\\.(log|info|debug|warn|error).*)/\\/\\/\\2/i' #{javascript_path}"
end</code></pre>
<p><b>To Strip Out:</b></p>
<pre><code>
task :after_update_code, :roles =&gt; :app do
  javascript_path = File.join(release_path, 'public', 'javascripts', '*.js')
  run "sed -i -r 's/(\\/\\/|^)(\\s*console\\.(log|info|debug|warn|error).*)//i' #{javascript_path}"
end</code></pre>
<p>So instead of removing those debugging calls from the file, just leave them there and let Capistrano and <code>sed</code> strip them out for ya!</p>
<p>Talk about an easy life :3.</p>
<p><img src="http://static.aizatto.com/tango/16x16/emblems/emblem-important.png" alt="Important"/><b>Note:</b> This only works in the top level <code>javascripts</code> directory.</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://rails.aizatto.com/2007/07/29/remove-firebug-javascript-console-calls-on-deployment/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
