public
Fork of rubys/mars
Description: Yet Another Planet Refactoring
Homepage: http://intertwingly.net/blog/2007/12/19/Yet-Another-Planet-Refactoring
Clone URL: git://github.com/technomancy/mars.git
mars / test / cache / entry / intertwingly.net,2004,2851
100644 43 lines (41 sloc) 8.554 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<entry xmlns:thr='http://purl.org/syndication/thread/1.0' xmlns='http://www.w3.org/2005/Atom'>
    <id>tag:intertwingly.net,2004:2851</id>
    <link href='http://intertwingly.net/blog/2008/05/29/Scaling-Rails-Down' rel='alternate'/>
    <link href='http://intertwingly.net/blog/2851.atom' rel='replies' thr:count='4' thr:updated='2008-06-13T07:28:38-04:00'/>
    <title>Scaling Rails... Down</title>
    <summary type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'><p>As I proceed with updating <a href='http://pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition'>Agile Web Development with Rails</a> to support Rails 2.x, I have become impressed with how Rails has become even <b>more</b> focused on scaling <b>down</b> than it was in Rails 1.x.  Some of the credit goes to Rails itself (changes in scaffolding, migration), but much of the credit goes to making sqlite3 the default.</p>
<p>I am having difficulty expressing the concept, but I have two examples that I can express in code.</p></div></summary>
    <content type='xhtml'><div xmlns='http://www.w3.org/1999/xhtml'><svg viewBox='0 0 100 100' height='100' xmlns='http://www.w3.org/2000/svg' width='100'>
<path d='M1,12c0-7,4-11,11-11h87v87c0,5-5,11-11,11h-87z' stroke='#712' stroke-width='2' fill='#723'></path>
 
<path d='M13,22h80v60l-40,15l-39-16z' fill='#a33'></path>
<path d='M25,2l27,18l28,11l18,48v-77z' fill='#a54'></path>
<path d='M80,31l19,8l-9,20z' fill='#d5a67c'></path>
<path d='M78,2l2,29l19,8z' fill='#c98'></path>
<path d='M53,20l25-18l2,29z' fill='#b76'></path>
<path d='M90,58l8,20l-20,7z' fill='#b65'></path>
<path d='M98,78l-47,18l2,2h36zM25,2l28,18l-27,10l-12,27l-11-19z' fill='#a72d3a'></path>
<path d='M14,56l-11,23l26,6z' fill='#924'></path>
 
<path d='M93,23c-38-35-78,17-77,69h41c-17-52,7-81,35-67zM62,80l-7-1l2,5h7zM15,72l-7-1l-2,7l8,1zM58,62l-5-3v5l6,3zM22,47l-7-3l-2,6l7,3zM59,48l-4-4l-1,4l4,4zM62,31l-2,4l3,3l1-3zM34,26l-4-3l-4,4l5,4zM73,25h-4l1,4l3-1zM86,24h-4v2h4zM87,14l-4-3v3l4,2zM50,13l-3-4l-4,3l3,4zM68,10l-2-4h-5l2,4z' fill='#FFF'></path>
</svg>
<p>As I proceed with updating <a href='http://pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition'>Agile Web Development with Rails</a> to support Rails 2.x, I have become impressed with how Rails has become even <b>more</b> focused on scaling <b>down</b> than it was in Rails 1.x.  Some of the credit goes to Rails itself (changes in scaffolding, migration), but much of the credit goes to making sqlite3 the default.</p>
<p>What I mean by scaling down is to places where I would not have previously thought it was worth the time or effort to build a web application.  In many cases, I am talking single user, single table applications whose usefulness may last only a few months or even days.  The ability to go from concept to running code preloaded with live data in five minutes or less is truly a game changer for me.</p>
<p>I am having difficulty expressing the concept, but I have two examples that I can express in code.  It is said that Rails itself was factored out of live running application, and perhaps after I create a few more examples, I will be able to fully see the commonality and be able to build a generator and/or a small wizard application (built on Rails, natch).</p>
<p>The six steps to a running application are <code>rails application</code>, <code>cd application</code>, <code>ruby script/generate scaffold table attrs...</code>, <code>rake db:migrate</code>, <em>load</em> data, <code>ruby script/server</code>, and <em>tweak</em>.  The keys being <code>scaffold</code>, <em>load</em>, and <em>tweak</em>.</p>
<h3 id='errata'>Errata</h3>
<p>The first example is <a href='http://intertwingly.net/stories/2008/05/29/errata.rb'>errata</a>.  <a href='http://pragprog.com/'>Pragmatic Programmers</a> hosts a simple <a href='http://pragprog.com/titles/rails3/errata/'>errata</a> page that contains input that has been received to date beta of books.  As I’m working (sometimes offline), I like having the ability to annotate these records as to whether I have made the fix, am deferring the suggestion for now, or (for whatever reason) the fix is resolved another way.</p>
<p>So I define a model for an erratum consisting of three groups of attributes: ones that show up in the index and on the individual edit page, ones that are in the xml file but I’m not concerned about for the moment, and additional  attributes that represent annotation.</p>
<p>The “tweaks” include defining a virtual attribute in the model for a “beta_page” that combines the <code>title_release_reported_in</code> and <code>pdf_page</code> fields into one, highlights errata which were first seen within the last 24 hours, filter the index to only show issues which haven’t been categorized, turn off session support (as this is a single user application), and some minor CSS.</p>
<p>Loading is as simple as an xml parse of the <a href='http://pragprog.com/titles/rails3/errata/index.xml'>input document</a>, some minor type coercions, name mapping, and filtering, and into the database it goes.  This step can be rerun multiple times as it will only replace the columns which were originally sourced from the document, and will only add new rows when a new errata_id is encountered.</p>
<p><a href='http://intertwingly.net/stories/2008/05/29/errata.rb'>this code</a> does all that and launches a server.  Up and running in five minutes indeed.  And <a href='http://intertwingly.net/stories/2008/05/29/report.html.erb'>additional reports</a> are easy enough to add later.</p>
<h3 id='agenda'>Agenda</h3>
<p>The second example is <a href='http://intertwingly.net/stories/2008/05/29/agenda.rb'>agenda</a>.  The <a href='http://www.apache.org/foundation/board/'>ASF Board</a> meetings each have an agenda that is of the same basic format as the <a href='http://www.apache.org/foundation/board/calendar.html'>minutes</a>, but with room for individual directors to leave comments and to “pre-approve” individual reports.  As an officer, director, and secretary, I need to interleave reporting, participating, and recording activities all the while coping with a document that is in a decidedly non-linear format.  I’ve been able to cope using browser tabs and having a <a href='http://intertwingly.net/blog/2008/03/08/Switched'>second monitor</a> has been a real blessing, but having a single application that enables me to navigate within the document and record comments inline would be helpful.</p>
<p>Once again, there are three groups of attributes involved: ones that show only in the index, ones that show both in the index and on the individual report pages, and ones that represent annotations.</p>
<p>Tweaks include color coding the rows based on the status of the report (missing, ready for review, approved with comments, and simply approved) and changing the flow in the controller to move onto the next report after an update is made.</p>
<p>The loading step is the most difficult one here as it involves some gnarly regular expressions and, in the case of Additional Officer Reports and Committee Reports requires two passes.  The actual interaction with the database is trivial.</p>
<p>The “market” for the above application is likely only “one”, or at most a dozen or so (directors plus guests), and as such would probably still remain unwritten except for the fact that I was bored on a plane ride out and this gave me something to do.  Future work would include expanding to the “prep” stage (i.e., highlight which reports are ready but have not been reviewed by me just yet), and to the “publish” state (first pass generation of the report based on the agenda and annotations).</p></div></content>
    <updated>2008-05-29T13:58:37-04:00</updated>
  <source xmlns:planet='http://planet.intertwingly.net/'><planet:Intertwingly>http://intertwingly.net/blog/index.atom</planet:Intertwingly><link href='http://intertwingly.net/blog/index.atom' rel='self'/><id>http://intertwingly.net/blog/index.atom</id><icon>http://intertwingly.net/favicon.ico</icon><title>Sam Ruby</title><subtitle>It’s just data</subtitle><author>
    <name>Sam Ruby</name>
    <email>rubys@intertwingly.net</email>
    <uri>http://intertwingly.net/blog/</uri>
  </author><updated>2008-06-27T10:49:16-04:00</updated><link href='http://intertwingly.net/blog/' rel='alternate'/><link href='http://creativecommons.org/licenses/BSD/' rel='license'/><link href='http://intertwingly.net/blog/index.atom' rel='self'/></source></entry>