<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>f3yourmind &#187; Ruby</title>
	<atom:link href="http://aslamkhan.net/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://aslamkhan.net</link>
	<description>"There are no limits. There are only plateaus, and you must not stay there, you must go beyond them." - Bruce Lee</description>
	<lastBuildDate>Wed, 01 Sep 2010 22:25:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Gotcha! (side-effects really pain a lot)</title>
		<link>http://aslamkhan.net/software-development/gotcha-side-effects-really-pain-a-lot/</link>
		<comments>http://aslamkhan.net/software-development/gotcha-side-effects-really-pain-a-lot/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 20:37:40 +0000</pubDate>
		<dc:creator>Aslam</dc:creator>
				<category><![CDATA[Architecture and Development]]></category>
		<category><![CDATA[buildr]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[rjb]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[side effects]]></category>

		<guid isPermaLink="false">http://aslamkhan.net/?p=286</guid>
		<description><![CDATA[I just upgraded to Snow Leopard and installed buildr which failed miserably.
/Library/Ruby/Gems/1.8/gems/rjb-1.1.9/lib/rjbcore.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/rjb-1.1.9/lib/rjbcore.bundle, 9): no suitable image found.  Did find: (LoadError)
/Library/Ruby/Gems/1.8/gems/rjb-1.1.9/lib/rjbcore.bundle: no matching architecture in universal wrapper - /Library/Ruby/Gems/1.8/gems/rjb-1.1.9/lib/rjbcore.bundle
It turns out that I needed to rebuild rjb, the ruby-java bridge, but that failed too.
extconf.rb:48: JAVA_HOME is not set. (RuntimeError)
I was certain that JAVA_HOME was [...]]]></description>
			<content:encoded><![CDATA[<p>I just upgraded to Snow Leopard and installed <a href="http://buildr.apache.org">buildr</a> which failed miserably.</p>
<blockquote><p><code>/Library/Ruby/Gems/1.8/gems/rjb-1.1.9/lib/rjbcore.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/rjb-1.1.9/lib/rjbcore.bundle, 9): no suitable image found.  Did find: (LoadError)<br />
/Library/Ruby/Gems/1.8/gems/rjb-1.1.9/lib/rjbcore.bundle: no matching architecture in universal wrapper - /Library/Ruby/Gems/1.8/gems/rjb-1.1.9/lib/rjbcore.bundle</code></p></blockquote>
<p>It turns out that I needed to rebuild <a href="http://rubyforge.org/projects/rjb/">rjb</a>, the ruby-java bridge, but that failed too.</p>
<blockquote><p><code>extconf.rb:48: JAVA_HOME is not set. (RuntimeError)</code></p></blockquote>
<p>I was certain that <code>JAVA_HOME</code> was definitely set and it was pointing to the 64-bit Apple 1.6 JDK.  Digging in <code>extconf.rb</code>, it finds <code>JAVA_HOME</code> from the <code>ENV</code> hash</p>
<blockquote><p><code>javahome = ENV['JAVA_HOME']</code></p></blockquote>
<p>So, nothing weird about that too!  What&#8217;s going on?  I was installing buildr like this</p>
<blockquote><p><code>sudo gem install buildr</code></p></blockquote>
<p>The problem is that once you <code>sudo</code>, you are running with another environment, one without the <code>JAVA_HOME</code> variable.  So, the quick fix is simply</p>
<blockquote><p><code>sudo env JAVA_HOME=$JAVA_HOME gem install '1.1.9' rjb<br />
sudo env JAVA_HOME=$JAVA_HOME gem install buildr</code></p></blockquote>
<p>I completely forgot about this side-effect.  Like all side-effects, it was painful &#8211; it just cost me an hour of  digging around looking at all sorts of other things.  But, more importantly, breaking fundamental assumptions (e.g. my environment is the <code>sudo</code>&#8217;s environment) and zoning in on the root cause of the problem resulted in a very simple solution.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Faslamkhan.net%2Fsoftware-development%2Fgotcha-side-effects-really-pain-a-lot%2F&amp;linkname=Gotcha%21%20%28side-effects%20really%20pain%20a%20lot%29"><img src="http://aslamkhan.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://aslamkhan.net/software-development/gotcha-side-effects-really-pain-a-lot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Measuring the Clarity of Requirements</title>
		<link>http://aslamkhan.net/software-development/measuring-the-clarity-of-requirements/</link>
		<comments>http://aslamkhan.net/software-development/measuring-the-clarity-of-requirements/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 12:47:41 +0000</pubDate>
		<dc:creator>Aslam</dc:creator>
				<category><![CDATA[Architecture and Development]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[requirements]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[use cases]]></category>

		<guid isPermaLink="false">http://aslamkhan.net/?p=121</guid>
		<description><![CDATA[The last two geeky conversations I had, stumbled upon the same thing &#8211; how do you measure the effectiveness of requirements in describing the business to the business and describing the specification to the developer?
So, I posed the question &#8220;How far away are you from executing your requirements?&#8221;.  If you are going to go [...]]]></description>
			<content:encoded><![CDATA[<p>The last two geeky conversations I had, stumbled upon the same thing &#8211; how do you measure the effectiveness of requirements in describing the business to the business and describing the specification to the developer?</p>
<p>So, I posed the question &#8220;How far away are you from executing your requirements?&#8221;.  If you are going to go through various steps and stages to get to compilation and then execution, then every step is an opportunity for valuable information being lost in translation.  If you can compile your requirements immediately then nothing will be lost.</p>
<p>Each additional step between requirements description and compilation and execution is an opportunity to confuse the user and the developer and everyone in between.  That&#8217;s why fully dressed <a href="http://en.wikipedia.org/wiki/Use_case">use cases</a> are not so effective as fully dressed <a href="http://dannorth.net/introducing-bdd">behavior driven stories</a>.  And that&#8217;s why BDD is very agile and a great asset in DDD and use cases just don&#8217;t cut it anymore.</p>
<p>Right now, my favorite tool is <a href="http://wiki.github.com/aslakhellesoy/cucumber">Cucumber</a>.  I can execute the requirements and that raises the clarity ranking of my requirements super high.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Faslamkhan.net%2Fsoftware-development%2Fmeasuring-the-clarity-of-requirements%2F&amp;linkname=Measuring%20the%20Clarity%20of%20Requirements"><img src="http://aslamkhan.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://aslamkhan.net/software-development/measuring-the-clarity-of-requirements/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JRuby with Andrea Provaglio</title>
		<link>http://aslamkhan.net/events/jruby-with-andrea-provaglio/</link>
		<comments>http://aslamkhan.net/events/jruby-with-andrea-provaglio/#comments</comments>
		<pubDate>Tue, 18 Dec 2007 17:21:10 +0000</pubDate>
		<dc:creator>Aslam</dc:creator>
				<category><![CDATA[Conferences, Speaking Gigs, etc.]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JCSE]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[PBT]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://aslamkhan.net/uncategorized/jruby-with-andrea-provaglio/</guid>
		<description><![CDATA[PBT Group and the Johannesburg Centre for Software Engineering are hosting a JRuby master class led by Andrea Provaglio.  I met Andrea at the Software Architecture Workshop in Arosa, Switzerland this year and I cannot speak more highly of him.  Just check out his web site for details.  It&#8217;s not often that we get a chance to have such learned [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.pbt.co.za">PBT Group</a> and the <a href="http://www.jcse.org.za">Johannesburg Centre for Software Engineering</a> are hosting a JRuby master class led by <a href="http://andreaprovaglio.com/">Andrea Provaglio</a>.  I met Andrea at the Software Architecture Workshop in Arosa, Switzerland this year and I cannot speak more highly of him.  Just check out his web site for details.  It&#8217;s not often that we get a chance to have such learned architects and practitioners in South Africa.  Let&#8217;s take advantage of this opportunity.  The greater the support, the easier it is for us to pull in heavy hitters in this industry for future events.There is a class scheduled for Johannesburg on 16 January 2008 and Cape Town on 29 January 2008.  Registration is online at the JCSE <a href="http://www.jcse.org.za">website</a>.  Just follow the links from the front page.See you there!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Faslamkhan.net%2Fevents%2Fjruby-with-andrea-provaglio%2F&amp;linkname=JRuby%20with%20Andrea%20Provaglio"><img src="http://aslamkhan.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://aslamkhan.net/events/jruby-with-andrea-provaglio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get Cooking with JRuby on Rails</title>
		<link>http://aslamkhan.net/software-development/get-cooking-with-jruby-on-rails/</link>
		<comments>http://aslamkhan.net/software-development/get-cooking-with-jruby-on-rails/#comments</comments>
		<pubDate>Tue, 18 Dec 2007 16:35:54 +0000</pubDate>
		<dc:creator>Aslam</dc:creator>
				<category><![CDATA[Architecture and Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JRuby]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://aslamkhan.net/java/get-cooking-with-jruby-on-rails/</guid>
		<description><![CDATA[Some of the companies that I interact claim that they will never switch to Ruby on Rails (or just plain &#8216;ol Ruby) for that matter.  But with JRuby reaching 1.0 status (and currently on 1.0.2 with 1.1b1 already released) this changes the situation somewhat.  Now it is possible to develop Rails apps and [...]]]></description>
			<content:encoded><![CDATA[<p>Some of the companies that I interact claim that they will never switch to Ruby on Rails (or just plain &#8216;ol Ruby) for that matter.  But with JRuby reaching 1.0 status (and currently on 1.0.2 with 1.1b1 already released) this changes the situation somewhat.  Now it is possible to develop Rails apps and run it on your Java infrastructure that make use of native JDBC connections and a whole bunch more.<br />
<h3>Pre-requisites</h3>
<p>Since we want to run a Ruby on Rails app on a Java application server, we need to have a Java web container such as Tomcat, Jetty or Glassfish.  In my case, I&#8217;ll be dropping the app into into a Glassfish domain.  I guess that this should work just fine for Tomcat as well, but I have not verified this as yet.You also need a database and I will be using MySQL.  If you are going to use another database, you need to make sure that the ActiveRecord-JDBC adapter has been developed for the DB.  ActiveRecord is the ORM for Rails apps.  Currently, there are ActiveRecord-JDBC adaptors for HypersonicSQL, Derby, MySQL and PostgreSQL.  This is true for version 0.6 of ActiveRecord-JDBC.  For other adapters, you will need to specify a proper JDBC URL in your application&#8217;s database configuration file, <code>config/database.yml</code>.  This will make a lot more sense once you finish this exercise.All of the above (except or ActiveRecord, of course) should be stock standard goodies on any self-respecting Java development box.  With this place, let&#8217;s get cooking.<br />
<h3>Install JRuby</h3>
<p>Download the JRuby bin distribution from the JRuby downloads page. At the time of writing this, 1.1b1 has been released.  I am currently using the 1.02 release.  Unzip/untar the file to somewhere convenient, add an environment variable <code>JRUBY_HOME</code> to point to the extracted directory, and add <code>JRUBY_HOME/bin</code> to your path.
<pre>	/&gt; cd ~/tools	/&gt; tar xzvf jruby-bin-1.02.tar.gz</pre>
<pre><span style="white-space: pre" class="Apple-tab-span">	</span>/&gt; export JRUBY_HOME=~/tools/jruby-1.0.2</pre>
<pre><span style="white-space: pre" class="Apple-tab-span">	</span>/&gt; export PATH=$PATH:$JRUBY_HOME/bin</pre>
<p>You can verify your JRuby installation with:
<pre>	/&gt; jruby -v</pre>
<pre><span style="white-space: pre" class="Apple-tab-span">	</span>ruby 1.8.5 (2007-11-01 rev 4810) [i386-jruby1.0.2]</pre>
<p> You will notice two versions being reported.  The first tells us that the ruby implementation is version 1.8.5 and the second tells us that it is running on jruby 1.0.2 on i386 platform.  If you are new to ruby, then you need to know that there are different implementations of ruby, with the definitive one called MRI (Matz&#8217;s Ruby Implementation &#8211; Matz is the original author of ruby).  JRuby is an attempt at a complete port of MRI to Java, aiming to eliminate all dependencies on C libraries.  This is one of the significant points about JRuby: it is pure Java.<br />
<h3>Install RubyGems</h3>
<p>The closest Java equivalent of RubyGems  is Maven or Ant+Ivy.  Gems is a library and dependency management tool for ruby.  On a native ruby install, you would have to download and install RubyGems, but JRuby already has RubyGems rolled in.  Take a peek at JRUBY_HOME/bin and you should see an executable file called gem.  So, nothing more to do here.  What the heck, let&#8217;s verify that RubyGem is working.
<pre>	/&gt; jruby -S gem -v</pre>
<pre>	0.9.4</pre>
<p>If <code>$JRUBY_HOME/bin</code> is first in your path, then you can try <code>/&gt; gem -v</code>.  The <code>-S</code> tells jruby to run the command that follows from <code>$JRUBY_HOME</code>.For the ruby folk, you should realize that JRuby has rolled in RubyGems version 0.9.4 which is as fresh as it comes.The closest Java equivalent of RubyGems that I can think of is perhaps Maven or ANT+Ivy.  But RubyGems takes the prize hands-down for its absolute simplicity.  Install rake and Rails below and see what I mean.<br />
<h3>Install Rake</h3>
<p> Rake is a really good build tool for ruby (i.e a make for ruby, hence the goofy name).  Once you start writing rake build scripts, you will wonder why one earth you thought ANT is nice.  Anyway, let&#8217;s install rake.
<pre>	/&gt; jruby -S gem install rake</pre>
<h3>Install Rails</h3>
<p>Now that you&#8217;ve seen the goodness of RubyGems, install Rails and the ActiveRecord for JDBC.
<pre>	/&gt; jruby -S gem install rails -v 1.2.6 -y --no-rdoc --no-ri</pre>
<pre>	/&gt; jruby -S gem install activerecord-jdbcmysql-adapter --include-dependencies</pre>
<p>We are deliberately installing Rails version 1.2.6.  Rails 2.0.1 was released in early December 2007 and I have not taken 2.0.1 for a drive under jruby yet.  So, we&#8217;ll stick to version 1.2.6 which is still great.<br />
<h3>Get MySQL Ready</h3>
<p> We&#8217;re heading for the home straight with all this setup and configuration nonsense.  Just a couple of things to do.
<ul>
<li>Copy the MySQL JDBC driver to <code>$JRUBY_HOME/lib</code>.</li>
<li>Create a MySQL database called <code>testapp_development</code>.  Rails apps require three databases; one for development (suffixed <code>_development</code>), one for unit testing (suffixed _test and is wiped clean with every test run) and one for production (suffixed _production).  For this exercise, we will just use the development database with full rights given to the MySQL user <code>root</code> with no pasword.</li>
</ul>
<h3>Create the Rails App</h3>
<p>Now the fun starts! Finally!The next command will create a directory with the same name as your application.  So, change to a directory that will contain your rails applications.  In my case, I keep my applications in <code>~/projects/jruby</code>.
<pre>	/&gt; cd ~/projects/jruby</pre>
<pre>	/&gt; jruby -S rails testapp</pre>
<p>Now you should have a directory called <code>testapp</code>.  Let&#8217;s see if our app works. Yes, in rails-land, the app can already be fired up!
<pre>	/&gt; cd ~/projects/jruby/testapp</pre>
<pre>	/&gt; jruby script/server</pre>
<p>This fires up <code>webrick</code>, a built in http server with ruby support built in. Just point your browser to <code>http://0.0.0.0:3000</code> and you should see the Rails happy page.  Kill <code>webrick</code> by hitting <code>CTRL+C</code>.<br />
<h3>Link up to your database</h3>
<p>Edit the file <code>config/database.yml</code> and change it as follows. Note that the line <code>socket: /tmp/mysql.sock</code> must be removed.
<pre>	development:</pre>
<pre>  	  adapter: mysql</pre>
<pre>  	  database: testapp_development</pre>
<pre>  	  username: root</pre>
<pre>  	  password:</pre>
<p>and
<pre>	production:</pre>
<pre>  	  adapter: mysql</pre>
<pre>  	  database: testapp_development</pre>
<pre>  	  username: root</pre>
<pre>  	  password:</pre>
<p> YML files are files that store configuration using <a href="http://www.yaml.org">YAML</a>, which is a <em>&#8221; is a straightforward machine parsable data serialization format designed for human readability&#8221;</em>.Now, let us inform the Rails app that we are using <code>ActiveRecord-JDBC</code>.  Add the following to the file <code>config/environment.rb</code> just before the line <code>Rails::Initializer.run do |config|</code>.
<pre>  if RUBY_PLATFORM =~ /java/</pre>
<pre>    require 'rubygems'</pre>
<pre>    RAILS_CONNECTION_ADAPTERS = %w(jdbc)</pre>
<pre>  end</pre>
<h3>Create a table (the Rails way)</h3>
<p> Sure, we can write a simple SQL script to create the table we want, but for fun, let&#8217;s do it using some Rails sugar.  You can keep your app running in webrick and still do the this.  Just open up another command or shell, switch to your project directory and get going.  This is one of the nicest bits of Rails &#8211; you can do most things without a restart of your application server.
<pre>	/&gt; jruby script/generate migration AddGadgetsTable</pre>
<p>This should have created a file <code>db/migrate/001_add_gadgets_table.rb</code>.  Open this file and edit it as follows.
<pre>	class AddGadgetsTable &lt; ActiveRecord::Migration</pre>
<pre>	   def self.up</pre>
<pre>	      create_table :gadgets do |table|</pre>
<pre>	         table.column :name,  :string, :null =&gt; false</pre>
<pre>	         table.column :color, :string, :null =&gt; false</pre>
<pre>	      end</pre>
<pre>	   end</pre>
<pre>	   def self.down</pre>
<pre>	      drop_table :gadgets</pre>
<pre>	   end</pre>
<pre>	end</pre>
<p>After saving the file, run the following command to create the table.  Actually, we&#8217;re <em>migrating</em> our existing database to <em>version 001</em>!  Database refactoring is a definite goal of Rails.  It may not be perfect, but it is certainly better than maintaining a bunch of SQL files.
<pre>	/&gt; jruby -S rake db:migrate</pre>
<p> Even if you&#8217;ve never seen ruby before, the above is certainly readable and you can easily understand that we intend to create a table called <code>gadgets</code> with two columns <code>name</code> and <code>color</code>.  Actually, there are more than these two columns.  Have a look at the table structure and check that a primary key colum <code>id</code> has been added as well.<br />
<h3>Generate Scaffolding to maintain the table</h3>
<p>I know, I know, I know!  Code generation for anything but the most trivial of code can be dramatic for newbies but real code takes a lot more effort.  The point here is just to get some Rails code up and running so that we can deploy it in a Java application server.  So, please bear with me.
<pre>	/&gt; jruby script/generate scaffold gadget</pre>
<p>Fire up <code>webrick</code> and visit the URL <code>http://0.0.0.0:3000/gadgets</code>.  You should see a page with an empty list of gadgets and CRUD links.<br />
<h3>Get ready to WAR</h3>
<p>We need a few additional rake tasks to be able to build a WAR for our Rails application.  The Goldspike plugin for Rails does just that.  Let&#8217;s install the Goldspike plugin.
<pre>	/&gt; jruby script/plugin install \</pre>
<pre>		svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike</pre>
<p>All that&#8217;s required is to add the WAR dependency on the MySQL driver.  What&#8217;s great about Goldspike is that we can declare Maven dependencies.  Great combination: RubyGems for Ruby-land and Maven for JRuby-land!  Open the file <code>vendor/plugins/goldspike/lib/war_config.rb</code> and add the following line to the list of <code># default java libraries</code> block.
<pre>	add_java_library(maven_library ('mysql', 'mysql-connector-java', '5.0.5'))</pre>
<h3>Build the WAR</h3>
<p><span style="font-size: 19px; font-weight: bold" class="Apple-style-span"></span><span style="font-size: 19px; font-weight: bold" class="Apple-style-span"></span>Now build the WAR using rake.
<pre>	/&gt; jruby -S rake war:standalone:create</pre>
<p>If you look in the root of your application directory, there should be a file testapp.war<br />
<h3>Drop it into Glassfish</h3>
<p> Start your Glassfish domain, log in to the Glassfish admin console and click the <em>Deploy Web Application</em> link.  Browse to the <code>testapp</code> directory and select the <code>testapp.war</code> file.  If the app is not enabled, then select <code>testapp</code>, and click <em>Enable</em>.<br />
<h3>See it in action</h3>
<p>Point your browser to <code>http://localhost:8080/testapp</code>.  You should see the Rails happy page, and <code>http://localhost:8080/testapp/gadgets</code> has the CRUD for our <code>Gadget</code> object.<span style="font-style: italic" class="Apple-style-span">As easy as pie! And just as nice!</span></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Faslamkhan.net%2Fsoftware-development%2Fget-cooking-with-jruby-on-rails%2F&amp;linkname=Get%20Cooking%20with%20JRuby%20on%20Rails"><img src="http://aslamkhan.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://aslamkhan.net/software-development/get-cooking-with-jruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
