<?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>CyberFOX Software Inc. &#187; Ruby</title>
	<atom:link href="http://cyberfox.com/blog/category/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://cyberfox.com/blog</link>
	<description>Coding, Connections, and Other Bloggy Bits of Goodness</description>
	<lastBuildDate>Sat, 04 Feb 2012 10:21:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Top 7 projects I&#8217;m actively working on</title>
		<link>http://cyberfox.com/blog/172-top-7-projects-im-actively-working-on</link>
		<comments>http://cyberfox.com/blog/172-top-7-projects-im-actively-working-on#comments</comments>
		<pubDate>Sat, 04 Feb 2012 10:13:25 +0000</pubDate>
		<dc:creator>Cyberfox</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[MacRuby]]></category>
		<category><![CDATA[Objective C]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[sniping]]></category>

		<guid isPermaLink="false">http://cyberfox.com/blog/?p=172</guid>
		<description><![CDATA[Greetings, Recently I got a casual query from a user who was interested in what else I had going on. I do have a lot of projects that I work on, along with spending time supporting JBidwatcher.  What follows is a lightly edited version of what I told them&#8230; (1) Most obviously there is JBidwatcher [...]]]></description>
			<content:encoded><![CDATA[<p>Greetings,</p>
<p>Recently I got a casual query from a user who was interested in what else I had going on. I do have a lot of projects that I work on, along with spending time supporting JBidwatcher.  What follows is a lightly edited version of what I told them&#8230;</p>
<p><small>(1)</small> Most obviously there is <strong><a title="Free eBay sniping, bidding &amp; monitoring" href="http://www.jbidwatcher.com">JBidwatcher</a></strong> which I spend some time supporting every day via email, <a title="JBidwatcher discussion groups" href="http://forum.jbidwatcher.com">forum</a>, and the <a title="JBidwatcher support" href="http://help.jbidwatcher.com">support site</a>, and sadly a little less time developing, but if you&#8217;ve <a title="The home of CyberFOX Software, by Morgan Schweers" href="http://cyberfox.com">poked at my site</a> you&#8217;ve noticed that I&#8217;ve got several other projects listed.  There is also one or two that are <em>not</em> listed which I&#8217;ll talk about.</p>
<p><small>(2)</small> One of the most obvious other projects to JBidwatcher users is <strong><a title="Bid watching and sniping web app" href="http://my.jbidwatcher.com">My JBidwatcher</a></strong>.  It has its own configuration tab in JBidwatcher, and it&#8217;s pretty far along in terms of features.</p>
<p>Unfortunately I&#8217;ve not implemented the &#8216;Add Auction&#8217; command in My JBidwatcher yet, nor the ability to send snipes back to your desktop JBidwatcher instance.  All the capabilities to do it are in place, I just haven&#8217;t seen enough interest from users to implement it.  My JBidwatcher gets a very small number of occasional users, although it&#8217;s been <em>invaluable</em> in helping me debug JBidwatcher, especially recently with the &#8216;null&#8217; priced items problems.  You can link My JBidwatcher to your desktop app just by entering your account information (user name and password) into the JBidwatcher &#8216;My JBidwatcher&#8217; configuration.</p>
<p>I really want to make it work better, but I&#8217;ve not gotten a confident feel that folks want that capability, or what folks <em>would</em> like from a web interface to JBidwatcher, so I&#8217;m unsure about spending time working on it as opposed to other projects.</p>
<p><small>(3, 4)</small> As for <strong>Hacker&#8217;s Health</strong> (and the iPhone companion app <strong>Health Hacker</strong>)&#8230;  Heh!  In 2007 as part of learning Ruby on Rails, I built a health tracking application for myself.  I still use it, and I&#8217;d love others to see it, but it needs some cleanup before that happens.  Fast forward to 2010, when I built an iPhone application around communicating with Google Health, and storing stuff in their data format (which is crazy complex, because it had to support health data vaults, essentially).  Then I started working for Google, and put it on hold, because they were talking about doing one themselves and I didn&#8217;t want to step on any toes&#8230;  Now that I&#8217;m not working for Google anymore, and Google Health has sadly gone away, I&#8217;ve revived it and updated my web application and have started making the two of them talk to each other.  This project is lots of fun to build, and very useful as <em>every time</em> I actually put focus on my health it gets better.</p>
<p><small>(5)</small> One of the last of my publicly acknowledged projects, <strong>MacBidwatcher</strong> is an application I&#8217;m actively working on.  Right now it can load eBay auctions, trigger updates, shows thumbnails,  track them in folders, and you can drag and drop items between folders.  I&#8217;ve added the ability to log in, but only on ebay.com so far.  (No international support yet.)  I&#8217;ve got some prototype code that bids, but I need to build the user interface for bidding, then start adding features to support sniping.</p>
<p>MacBidwatcher is a <em>much</em> more Mac-like application than JBidwatcher though, and my plan is (eventually) to offer it on the Mac App Store, and maybe through non-MAS sales as well.  Even folks like me need to eat.</p>
<p><small>(6)</small> Not really discussed anywhere, is <strong>iBidwatcher</strong> which is an iPhone version of JBidwatcher.  It&#8217;s already got a few cool features (including secure over-the-air sync with JBidwatcher if you&#8217;re on a wireless network with a running JBidwatcher instance) but it&#8217;s severely hampered by the inability of iPhone applications to do anything in the background. This means it can&#8217;t keep the price of a listing up to date when not running.  I&#8217;ve written code to scrape eBay&#8217;s site on the iPhone, and it works great, but it can only run when you are in the app.  It also <em>cannot</em> snipe from the phone, because the phone would have to be on and the app running, which is counter to the idea of a sniping application, i.e. <em>you shouldn&#8217;t need to think about it</em>.  Instead I&#8217;m considering partnering with Gixen, and allowing you to place snipes on their service through iBidwatcher if you have a Gixen Mirror subscription.  Their price of $6/year seems reasonable, and I have a lot of respect for the person who runs it.</p>
<p><small>(7)</small> The least interesting to most JBidwatcher users is <a title="Simple outlining web app." href="http://www.outlinr.com/show/faq">Outlinr</a>, which has gotten sidelined as I deal with other projects.  It was a blast to build, and was functional for a while, but server upgrades and the relentless progress of browsers has made it no longer work.  I love outlining as a knowledge-capture model, and think it could be done <strong><em>SO</em></strong> much better than anyone is currently doing it, but I have to focus on projects that I know others are more immediately interested in.</p>
<p>I&#8217;d be very interested in <em>your</em> thoughts on the various projects I&#8217;ve described, and what you&#8217;d like to see out of them.  I&#8217;m always looking for more insights into what would be helpful and valuable.</p>
<p>&#8211;  Morgan Schweers, Cyber<strong>FOX</strong>!</p>
]]></content:encoded>
			<wfw:commentRss>http://cyberfox.com/blog/172-top-7-projects-im-actively-working-on/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How I Learned To Stop Worrying About Core Data And Love MacRuby</title>
		<link>http://cyberfox.com/blog/120-how-i-learned-to-stop-worrying-about-core-data-and-love-macruby</link>
		<comments>http://cyberfox.com/blog/120-how-i-learned-to-stop-worrying-about-core-data-and-love-macruby#comments</comments>
		<pubDate>Thu, 10 Feb 2011 11:18:22 +0000</pubDate>
		<dc:creator>Cyberfox</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[MacRuby]]></category>
		<category><![CDATA[Objective C]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://cyberfox.com/blog/?p=120</guid>
		<description><![CDATA[Greetings, I am not an expert Objective C, Cocoa, or Core Data coder. There, I admitted it. I expect some of the people viewing this will be, and I encourage you to let me know where I&#8217;ve gotten things wrong. I&#8217;m also sure my MacRuby style is&#8230;let&#8217;s call it idiosyntactic. Too long to fit in [...]]]></description>
			<content:encoded><![CDATA[<p>Greetings,<br />
<em>I am not an expert Objective C, Cocoa, or Core Data coder.</em>  There, I admitted it.  I expect some of the people viewing this <em>will</em> be, and I encourage you to let me know where I&#8217;ve gotten things wrong.  I&#8217;m also sure my MacRuby style is&#8230;let&#8217;s call it idiosyntactic.</p>
<h2>Too long to fit in the margins of this book</h2>
<p>My journey starts with Matt Aimonetti&#8217;s excellent <a href="http://ofps.oreilly.com/titles/9781449380373/index.html">MacRuby: The Definitive Guide</a>, and it&#8217;s <a href="http://ofps.oreilly.com/titles/9781449380373/ch07.html">Core Data chapter</a>.  It&#8217;s a really good introduction to Core Data, but I needed something a bit deeper and more advanced.  My dream, of course, would be to use Core Data with Active Record&#8217;s ease of use.  Core Data is really complex, though.  <a href="http://www.amazon.com/gp/product/1934356328?ie=UTF8&#038;tag=cybersoftwinc-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1934356328">Books have been written</a><img src="http://www.assoc-amazon.com/e/ir?t=cybersoftwinc-20&#038;l=as2&#038;o=1&#038;a=1934356328" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> on the subject; and yet my complete exposure to it has been writing a few Objective C iPhone applications for my own use.</p>
<h2>My problem</h2>
<p>It&#8217;s always best to start with a relatively simple action, and figure out how to build on that.  My initial problem to solve was allowing the user to select a Category from an outline view on the left (iTunes style) and pull up a list of the items in that Category in a table view in the main part of the UI, like so:<br />
<center><a href="http://cyberfox.com/blog/wp-content/uploads/2011/02/macbidwatcher.png"><img src="http://cyberfox.com/blog/wp-content/uploads/2011/02/macbidwatcher.png" alt="MacBidwatcher screenshot with an outline view on the left and a table on the right." title="MacBidwatcher" width="768" height="297" class="size-full wp-image-124" /></a></center></p>
<p>I&#8217;m sure I could do this a number of ways, and it&#8217;s probably even possible to make it work with the standard NSArrayController like in MacRuby: The Definitive Guide, but there are a number of places where it won&#8217;t work as well, such as when I want to find the item ending the soonest from all Categories, or load and modify specific Auction items during updates or when the user chooses to perform actions on individual items.  At that point, it&#8217;ll become necessary to do the Core Data handling &#8216;by hand&#8217;, and so I felt it&#8217;d be best not to start with something I was going to have to bypass anyway.</p>
<h2>The Data Model</h2>
<p>It may be helpful to sketch a simple data model, described using the data modeler in Xcode; some other models in the project have been elided for clarity:<br />
<center><a href="http://cyberfox.com/blog/wp-content/uploads/2011/02/datamodel.png"><img src="http://cyberfox.com/blog/wp-content/uploads/2011/02/datamodel.png" alt="MacBidwatcher&#039;s Data Model for Categories and Auctions" title="Data Model" width="341" height="276" class="size-full wp-image-125" /></a></center></p>
<p>Because of the reciprocal relationship between Category and Auction, I could simply load a Category with a particular name, and then refer to <code style="color: black">category.auctions</code> to get the list (in Core Data form) of Auction objects associated with that category.  Adding <code style="color: black">.allObjects</code> returns the actual objects as an array for easy referencing in a TableView.  <small>(This is not efficient, but I&#8217;m trying to get the code working right now; I&#8217;ll manage efficiency once I&#8217;ve gotten it in users hands.)</small></p>
<h2>MacRuby vs. Objective C</h2>
<p>The Objective C (that I&#8217;ve written) to do a similar load <a href="http://gist.github.com/818176">takes about 80 lines of code</a>; I&#8217;m not embedding it because it&#8217;s too long, and it only loads by name.  You can go take a look; it&#8217;s pretty straightforward.  Unlike the Objective C version, the Ruby code can load by any attribute dynamically, and has additional features like limits and offsets.</p>
<p>This is the core of my code when the user clicks a category/folder on the left:<br />
<small><script src="https://gist.github.com/818166.js"></script></small></p>
<p>The key code being referenced is this:<br />
<span style="margin-left: 20px; color: black;"><code><span style="color: teal">@current_category</span> = <span style="color: teal">Category</span>.find_first(context, by_name:category_name)</code></span><br />
It&#8217;s roughly equivalent to the Objective C code (extracted from the app that uses my ObjC code above):<br />
<span style="margin-left: 20px; color: black;"><code><span style="color: teal">NSArray</span> *cats = [<span style="color: teal">Category</span> findByName:category fromContext:managedObjectContext];</code></span><br />
The main difference is that the Objective C code requires a different method for each <code style="color: black">findBy*</code> that you want to do, whereas the MacRuby code uses the fact that its parameters are really just hash entries using the &#8216;:&#8217; syntax for faux named parameters.  So, for example, while this code is doing a <code style="color: black">find_first</code>, if it were to use <code style="color: black">find_all</code> it could also pass <code style="color: black">..., limit:20, offset:7)</code> if you wanted to get 20 items starting at the 7th.</p>
<h2>The Magic</h2>
<p>The magic, of course, happens in <code>entity.rb</code> which looks like this:</p>
<p><small><script src="http://gist.github.com/818182.js"></script></small></p>
<p><small>It references <code>inheritable_attrs.rb</code> which is available as a <a href="http://gist.github.com/820211">gist of its own</a></small></p>
<p>One important part that any entity needs to get is a &#8216;context&#8217;, which is actually a managed object context.  Fortunately when you create a Mac Ruby project using the MacRuby Core Data Application template, a context is available from the AppDelegate class.  You may notice that in my <a href="https://gist.github.com/818166">AuctionTableDatasource</a> there is: <code>attr_writer app_delegate</code> which doesn&#8217;t really do anything obvious.  That&#8217;s an &#8216;outlet&#8217; to refer to the AppDelegate; using Interface Builder control-click-and-drag from your data source to the App Delegate, and choose the app_delegate outlet to link it up.  The default Core Data AppDelegate class instantiates a Managed Object Context which is essentially a link to your Core Data database.  It needs to be passed in to code which is going to interact with data from the database, which is why each of the public methods in <a href="http://gist.github.com/818182"><code>entity.rb</code></a> takes a context as their first parameter.</p>
<h2>A MacRuby Caveat</h2>
<p>I mildly disagree with the default MacRuby Core Data Application template which creates an XML-based Core Data app; specifically it creates a file with the extension of <code>.xml</code> and passes <code>NSXMLStoreType</code> as the persistent store type.  I believe it should pass a <code>.sqlite</code> file extension and use <code>NSSQLiteStoreType</code> as the storage type.  For small applications, it may not matter, but if you feel you&#8217;re likely to be storing enough data that handling Core Data by hand will be necessary, then you&#8217;re going to want the SQL-based storage type.  The typical recommendation is to start with an XML type and switch to SQL when you&#8217;re going to release, nominally because XML is easier to read.  I dispute that, though, because there are slight behavioral differences, such as the XML storage type keeping the entire object graph in memory and reports of subtly different handling of (<a href="http://www.cocoabuilder.com/archive/cocoa/192798-core-data-nssqlitestoretype-problem.html">generally incorrectly specified</a>) relations.  If you want to use an SQLLite backed database, you&#8217;ll want to fix up <code>AppDelegate.rb</code> once you&#8217;ve created your project.</p>
<h2>Conventions and Features</h2>
<p>I know there&#8217;s a lot of disagreement over Active Record&#8217;s design, but I happen to like it a lot, and many of the guidelines of Rails creep into my code.  I especially like the presumption that there&#8217;s an easy way to do whatever you&#8217;re doing, that the code handles for you automatically, but if you want to fight the convention, you can; it just won&#8217;t be as clean.  There&#8217;s a lot of &#8216;convention&#8217; involved in the <code>Entity</code> class, especially in the presumptions that you&#8217;ll have model classes which are named identically (including case!) to the core data models you&#8217;ve created, i.e. generally with the first letter uppercased.  You should be able to override that by setting the <code>entity_name</code> in your subclasses using<code>
<pre>require 'entity'
Class OddlyNamedModel < Entity
  self.entity_name = 'oddly_named_model'
.
.
.
</pre>
</pre>
<p></code>but it&#8217;s not something you should do lightly, or at all if you&#8217;re creating a new project, and embarrassingly, I haven&#8217;t tested it.</p>
<h4>Attributes</h4>
<p>Attribute names were something else to deal with; I typically name my attributes in lower case while, as mentioned, my entities have their first letter capitalized.  So my <code>Category.find_first(context, by_name:category_name)</code> method will look for an attribute called &#8216;<code>name</code>&#8216;.  I am aware that some people capitalize the first letter of their attributes, so: <code>Category.find_first(context, byName:category_name)</code> would work if you have an attribute called &#8216;<code>Name</code>&#8216; and looks very Objective C-ish.</p>
<h4>Limits and Offsets</h4>
<p>It&#8217;s straightforward to index into your results, using <code>Category.find_all(context, by_name:common_name, offset:20, limit:10)</code>; this would search for all instances that have <code>common_name</code> in their <code>name</code> attribute, and then starting from the 20th, pull down 10 of them.  In SQLLite terms, this translates into something approximately like: <code>SELECT * FROM ZCATEGORY WHERE  NAME = ? LIMIT 10 OFFSET 20</code></p>
<h4>Conditions (the escape hatch)</h4>
<p>Another useful feature is a <code>conditions</code> key, which provides one entry which is raw predicate logic, essentially.  An example for finding all categories that end in &#8216;nt&#8217; would be: <code>Category.find_all(context, conditions:['name like %@', 'nt'])</code> which translates in SQLLite terms to: <code>SELECT * FROM ZCATEGORY WHERE  NSCoreDataLike( ZNAME, ?, 0)</code></p>
<h4>Debugging</h4>
<p>One incredibly useful built-in capability (and the source of the above approximations of the commands issued by Core Data) I&#8217;ve found for doing debugging of SQLLite-based Core Data code is to pass <code>-com.apple.CoreData.SQLDebug 1</code> to the application from the command line, in order to view the queries as they&#8217;re being done.  From the command line, in the root of your app directory, this would look something like this <code>
<pre>bash$ build/Release/MyApp.app/Contents/MacOS/MyApp -com.apple.CoreData.SQLDebug 1</pre>
<p></code></p>
<h2>Conclusion</h2>
<p>I&#8217;ve tried to make an extremely simple class that I can subclass for my entities, that allows me to do straightforward find operations in a way that doesn&#8217;t feel overly complex, and fits in a Ruby-ish style.  It&#8217;s working so far for my code, but I can&#8217;t promise it&#8217;ll work for everybody&#8217;s.  Especially if you&#8217;re facing down historical schemas, or other issues, my defaults are probably not going to be appropriate for you.  It&#8217;s definitely less code than the Objective C equivalent, and feels&#8230;more comfortable for me.</p>
<p>I&#8217;m VERY interested in feedback, and improving this code.  As I stated at the outset, the best I could be considered is a hobbyist Objective C coder, and I&#8217;m only just starting to dig into the power that MacRuby has.  Please feel free to provide pointers, comments, ideas, features, or (if necessary) derision.  Especially feel free to fork <a href="https://gist.github.com/818182"><code>entity.rb</code></a> and make corrections or additions as you see fit.</p>
<p>&#8211;  Morgan Schweers, Cyber<b>FOX</b>!</p>
<p><strong>Update:</strong> A friend and <em>quite excellent</em> Objective C developer <a href="http://github.com/ddb">David Brown</a> provided his own take on the Entity concept; according to him it&#8217;s untested and needs a few tweaks, but the basic concept should work equally well; check it out on <a href="https://gist.github.com/821456">his own gist of entity.m</a>. It&#8217;s like a Rosetta stone between MacRuby and Objective C!</p>
]]></content:encoded>
			<wfw:commentRss>http://cyberfox.com/blog/120-how-i-learned-to-stop-worrying-about-core-data-and-love-macruby/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>The three kinds of Rails migrations</title>
		<link>http://cyberfox.com/blog/54-the-three-kinds-of-rails-migrations</link>
		<comments>http://cyberfox.com/blog/54-the-three-kinds-of-rails-migrations#comments</comments>
		<pubDate>Sat, 23 May 2009 01:21:56 +0000</pubDate>
		<dc:creator>Cyberfox</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[migrations]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.cyberfox.com/blog/?p=54</guid>
		<description><![CDATA[Greetings, What alternative do you suggest for using models in migrations? I was in several situations where I had to not only change the underlying db structure but change the contained data, too. Data changes, especially moving data around, are almost always rake task-worthy in my experience. The other side of that, populating large amounts [...]]]></description>
			<content:encoded><![CDATA[<p>Greetings,</p>
<p style="padding-left: 30px;"><em>What alternative do you suggest for using models in migrations? I was in several situations where I had to not only change the underlying db structure but change the contained data, too.</em></p>
<p>Data changes, especially moving data around, are almost always rake task-worthy in my experience.</p>
<p>The other side of that, populating large amounts of seed data into new databases, is a difficult task no matter the method; seed_fu attempted to deal with it, but it’s not an optimal solution and pretty old. I’m not even sure if it works anymore. It’s worse if you need the seed data to be from a legacy database in tests (e.g. a nutritional database). Reloading lots of data each time a clone_structure_to_test is done makes your tests very slow.</p>
<p>I break down migrations into three kinds; structural (tables, columns, indices, etc.), data (pre-populating tables, etc.) and procedural (moving data around, recalculating counts, etc.). The first is what I strive to limit migrations to. I feel like there should be a good answer for the second and Rails 3.0 has a &#8216;Simplest Thing That Can Work&#8217; feature in <span class="status-body"><span class="entry-content"> Rails <a title="This is also known as the &quot;Stop Putting Gawd Damn Seed Data In Your Migrations&quot; feature [DHH]" href="http://github.com/rails/rails/commit/4932f7b38f72104819022abca0c952ba6f9888cb">commit #4932f7b</a></span></span>. The third, I try to relegate to rake tasks that are usually run once, on deployment of the branch.</p>
<p>The procedural tasks don’t need to be run when building a fresh database, because there isn’t legacy data to correct. That’s why you can usually define the model in the migration to force it to work even if the real model is gone or renamed; there’s no data, so the operations often don’t matter. If they don’t NEED to be run when building a fresh database, I try not to put them in the migrations.</p>
<p>It’s not ‘hard and fast’, because I usually work in startups to small companies, where dogma doesn’t work so well. Imagine, though, a large and thin piece of foam. It’s flexible, and you can make it into all sorts of shapes, and yet it’s simple. Each time you add code that makes reasonable changes in the future painful, it’s like putting a thin glass rod into the foam. It’s still flexible, but there’s some bends you can’t do without breaking. Add too many and you’ve got an inflexible and brittle object, no matter how dynamic the base material is.</p>
<p>The fear of breaking things by changing the code is deeply demotivating for everyone.</p>
<p>I know I waterboarded that analogy, but hopefully it makes sense…</p>
<p>—  Morgan Schweers, Cyber<strong>FOX</strong>!</p>
]]></content:encoded>
			<wfw:commentRss>http://cyberfox.com/blog/54-the-three-kinds-of-rails-migrations/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Approaching an inherited Rails codebase</title>
		<link>http://cyberfox.com/blog/56-approaching-an-inherited-rails-codebase</link>
		<comments>http://cyberfox.com/blog/56-approaching-an-inherited-rails-codebase#comments</comments>
		<pubDate>Fri, 22 May 2009 06:20:29 +0000</pubDate>
		<dc:creator>Cyberfox</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[startup]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.cyberfox.com/blog/?p=56</guid>
		<description><![CDATA[Greetings, [Edit: Since writing this article up back in early March, I've moved on from this job. The folks who are now maintaining it at least know where the pain points are, can run migrations safely, deploy it locally, and to dev servers, and to the main deployment area.  It's a working app, although I [...]]]></description>
			<content:encoded><![CDATA[<p>Greetings,</p>
<p><small><em>[Edit: Since writing this article up back in early March, I've moved on from this job. The folks who are now maintaining it at least know where the pain points are, can run migrations safely, deploy it locally, and to dev servers, and to the main deployment area.  It's a working app, although I never got code coverage above about 45% at least the coverage was decent in the core app areas by the time I left.]</em></small></p>
<p><a title="A Fresh Cup" href="http://afreshcup.com/">Mike Gunderloy</a> had an interesting article entitled &#8216;<a href="http://afreshcup.com/2009/03/23/batting-clean-up/">Batting Clean-up</a>&#8216;, which was very timely for me.  I’ve just started maintaining and trying to improve a Rails app developed by an ‘outsourced’ group. The only tests were the ones generated automatically by ‘restful authentication’, and they were never maintained, so they didn’t come close to passing. Swaths of the program are written in terribly complex (and sometimes computed) SQL, migrations didn’t bring up a fresh database (poor use of acts_as_enumerated causes great hurt), and vendor/plugins should have just had one named ‘kitchen_sink’.</p>
<p>It hurts to see Rails abused like that; you want to take the poor application under your arm and say, ‘It’ll be okay…we’ll add some tests and get you right as rain in no time!’, but you know you’d be lying…</p>
<p>I did much of what Mike <a title="Batting Clean-Up" href="http://afreshcup.com/2009/03/23/batting-clean-up/">described</a> (half the gems it used were config.gem’ed, the other half weren’t), vendor’ed rails (it breaks on newer than 2.1.0), and brought the development database kicking and screaming into life. There was no schema.rb, it had been .gitignore’d, and the migrations added data, used models, and everything else you can imagine doing wrong. (Including using a field on a model after adding that column in the previous line…I don’t know what version of Rails that ever worked on…) I didn’t want a production database; who knows what’s been done to that by hand. I want to know what the database is _supposed_ to look like; I can figure out the difference with production later.</p>
<p>Once the clean (only data inserted by migrations) dev database was up, I brought the site up to see if it worked. Surprisingly enough, it did; apparently they used manual QA as their only testing methodology. I appreciate their QA a lot; it means it’s a working application, even if it’s not going to help me refactor it.</p>
<p>I ran <a title="Flog (grotesque art, great tool)" href="http://ruby.sadi.st/Flog.html">flog</a> and <a href="http://ruby.sadi.st/Flay.html">flay</a> and looked at the pain points they found to get an idea how bad things might be. I picked an innocuous join table (with some extra data and functionality) to build the first set of tests for, which gave me insight into both sides of the join without having to REALLY dig into the ball of fur on either side. I viciously stripped all the ‘test_truth’ tests. I looked for large files that flog and flay hadn’t picked up to pore over. Check out custom rake tasks, because those often are clear stories and easy to quickly understand in a small context.</p>
<p>Checking out the deployment process tells you a lot also, although it turns out this was stock engine yard capistrano.</p>
<p>Skimming views (sort by size!) will tell you a lot also, especially when you find SQL queries being run in them…</p>
<p>Use the site for a little while, and watch the log in another window. Just let it skim by; if you’ve looked at log files much, things that seem wrong will jump out even if it’s going faster than you can really read.</p>
<p>In my case, the code’s mine now, so it’s my responsibility to make it better before anybody else has to touch it. I’ve got about a week of ‘free fix-it-up time’ before I need to start actually implementing new features and (thankfully) stripping out old ones… At my previous company, I was the guy pushing folks to test, now I’ve inherited a codebase with zero tests. Poetic justice, I suppose&#8230; <img src='http://cyberfox.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Good luck!</p>
<p>—  Morgan Schweers, Cyber<strong>FOX</strong>!</p>
]]></content:encoded>
			<wfw:commentRss>http://cyberfox.com/blog/56-approaching-an-inherited-rails-codebase/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hackety Hack!</title>
		<link>http://cyberfox.com/blog/27-hackety-hack</link>
		<comments>http://cyberfox.com/blog/27-hackety-hack#comments</comments>
		<pubDate>Fri, 27 Apr 2007 19:31:56 +0000</pubDate>
		<dc:creator>Cyberfox</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[passion]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.vixen.com/blog/2007/04/27/27</guid>
		<description><![CDATA[Greetings, Programming should be fun, it&#8217;s what gets us programmers into it in the first place, and it&#8217;s what keeps us going at it. Too many layers have been heaped on programming these days; most IDEs are oppressive, process-oriented beasts. I, and many other programmers, have been concerned about how the next generation of programmers [...]]]></description>
			<content:encoded><![CDATA[<p>Greetings,</p>
<p>Programming should be <strong><em>fun</em></strong>, it&#8217;s what gets us programmers into it in the first place, and it&#8217;s what keeps us going at it.</p>
<p>Too many layers have been heaped on programming these days; most IDEs are oppressive, process-oriented beasts.</p>
<p>I, and many other programmers, have been <a title="Why little Susie can&#039;t code..." target="_blank" href="http://www.whytheluckystiff.net/articles/theLittleCodersPredicament.html">concerned</a> about how the next generation of programmers are going to be introduced to the joy of programming when all the tools out there seem to suck the fun out of it.</p>
<p>Enter <a title="A really fun coding blog." target="_blank" href="http://redhanded.hobix.com/"><em>why the lucky stiff</em></a>, and <a title="Hackety Hack --  A programming environment for learning" target="_blank" href="http://hacketyhack.net/">Hackety Hack!</a>.  Taking one back to the days when programming was as easy as typing something in, and hitting enter.  <img src='http://cyberfox.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Hackety Hack! is about <a target="_blank" title="Included programming lessons..." href="http://code.whytheluckystiff.net/hacketyhack/wiki/HacketyLessons">learning to program</a>, and being able to do <a title="A blog in six lines of code!" target="_blank" href="http://hacketyhack.net/">really cool things</a> in a very few short lines.</p>
<p>I&#8217;ve been a fan of <a title="why the luck stiff" target="_blank" href="http://whytheluckystiff.net/"><em>_why</em></a> for a while, with a <a title="The best damn Ruby tutorial out there." target="_blank" href="http://poignantguide.net/ruby/">really wild approach to teaching Ruby</a>, and a lot of <a title="_why&#039;s coding archive" target="_blank" href="http://code.whytheluckystiff.net/">really interesting code</a>, and this is even cooler.</p>
<p>If you&#8217;re new to programming, or have kids, or just want to play with one of the simplest ways to write programs, <a title="easy introduction to programming" target="_blank" href="http://hacketyhack.net/get/">get Hackety Hack!</a></p>
<p>&#8211;  Morgan Schweers, CyberFOX!</p>
]]></content:encoded>
			<wfw:commentRss>http://cyberfox.com/blog/27-hackety-hack/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

