<?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>rel=me &#187; rails</title>
	<atom:link href="http://rel.me/t/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://rel.me</link>
	<description>programming, objective-c, cocoa, iphone, c</description>
	<lastBuildDate>Mon, 02 Aug 2010 20:09:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Freezing gems with Gem.use_path</title>
		<link>http://rel.me/2008/04/09/freezing-gems-with-gem-use-path/</link>
		<comments>http://rel.me/2008/04/09/freezing-gems-with-gem-use-path/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 17:12:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubygems]]></category>

		<guid isPermaLink="false">/2008/04/09/freezing-gems-with-gem-use-path</guid>
		<description><![CDATA[Edge rails now has gem dependency support built in, with tasks to freeze in vendor/gems. I have tried a bunch of different methods, and things like setting $GEM_HOME or using gemsonrails work well. But lately I have been using the Gem.use_paths method. If you put this in the config/environments rb: Gem.use_paths&#40;nil, &#91; &#34;#{RAILS_ROOT}/vendor/rubygems&#34; &#93;&#41; # [...]]]></description>
			<content:encoded><![CDATA[<p>Edge rails now has <a href="http://ryandaigle.com/articles/2008/4/1/what-s-new-in-edge-rails-gem-dependencies">gem dependency</a> support built in, with tasks to freeze in vendor/gems.</p>
<p>I have tried a bunch of different methods, and things like setting <tt>$GEM_HOME</tt> or using <a href="http://gemsonrails.rubyforge.org/">gemsonrails</a> work well. But lately I have been using the Gem.use_paths method.</p>
<p>If you put this in the config/environments rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Gem.<span class="me1">use_paths</span><span class="br0">&#40;</span><span class="kw2">nil</span>, <span class="br0">&#91;</span> <span class="st0">&quot;#{RAILS_ROOT}/vendor/rubygems&quot;</span> <span class="br0">&#93;</span><span class="br0">&#41;</span>
<span class="co1"># Gem.path is now:</span>
<span class="co1"># [&quot;/Users/ghandford/Projects/my_rails_proj/vendor/rubygems&quot;, &quot;/Library/Ruby/Gems/1.8&quot;]</span></pre></div></div>

<p>The vendor/rubygems directory is the same structure as system gems folder:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">  vendor/rubygems/cache
  vendor/rubygems/doc
  vendor/rubygems/gems
  vendor/rubygems/specifications</pre></div></div>

<p>The convention I use is any non-native gems get frozen with the project, and then all the native gems go in the system gem path, which gets you pretty close to clone/checkout and rake setup.</p>
<p>As far as unpacking and install gems, you just use <tt>gem install</tt> with GEM_HOME of your local project:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span class="re2">GEM_HOME</span>=<span class="sy0">`</span><span class="kw3">pwd</span><span class="sy0">`/</span>vendor<span class="sy0">/</span>rubygems gem <span class="kw2">install</span> capitate</pre></div></div>

<p>A benefit of the use_paths method is that you can create scripts in your Rails project that use gems frozen in your project (and not necessarily have to require rails or environment.rb to get at them).</p>
<pre>
./script/my_non_rails_script
</pre>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span class="kw3">require</span> <span class="st0">'rubygems'</span>
  Gem.<span class="me1">use_paths</span><span class="br0">&#40;</span><span class="kw2">nil</span>, <span class="br0">&#91;</span> <span class="kw4">File</span>.<span class="me1">dirname</span><span class="br0">&#40;</span><span class="kw2">__FILE__</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;/../vendor/rubygems&quot;</span> <span class="br0">&#93;</span><span class="br0">&#41;</span></pre></div></div>

<p>Has anyone else tried this before?</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2008/04/09/freezing-gems-with-gem-use-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx conf with alternate cache dir</title>
		<link>http://rel.me/2008/01/07/nginx-conf-with-alternate-cache-dir/</link>
		<comments>http://rel.me/2008/01/07/nginx-conf-with-alternate-cache-dir/#comments</comments>
		<pubDate>Mon, 07 Jan 2008 07:25:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">/2008/01/07/nginx-conf-with-alternate-cache-dir</guid>
		<description><![CDATA[Its a good idea to use an alternate cache directory in rails (in your environment.rb): config.action_controller.page_cache_directory = RAILS_ROOT + &#34;/public/cache/&#34; This makes it easier to sweep. To setup nginx to pick up from a rails alternate cache directory like public/cache, I used: if ($http_user_agent ~* &#34;(iPhone&#124;iPod)&#34;) { rewrite ^/$ /iphone break; proxy_pass http://mongrel-pt; break; } [...]]]></description>
			<content:encoded><![CDATA[<p>Its a good idea to use an alternate cache directory in rails (in your environment.rb):</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">config.<span class="me1">action_controller</span>.<span class="me1">page_cache_directory</span> = RAILS_ROOT <span class="sy0">+</span> <span class="st0">&quot;/public/cache/&quot;</span></pre></div></div>

<p>This makes it easier to sweep. To setup nginx to pick up from a rails alternate cache directory like public/cache, I used:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">if ($http_user_agent ~* &quot;(iPhone|iPod)&quot;) {
  rewrite ^/$ /iphone break;
  proxy_pass http://mongrel-pt;
  break;
}
&nbsp;
if (-f $request_filename) {
  break;
}
&nbsp;
if (-f $document_root/cache/$uri/index.html) {
  rewrite (.*) /cache/$1/index.html break;
}
&nbsp;
if (-f $document_root/cache/$uri.html) {
  rewrite (.*) /cache/$1.html break;
}
&nbsp;
if (-f $document_root/cache/$uri) {
  rewrite (.*) /cache/$1 break;
}
&nbsp;
if (!-f $request_filename) {
  proxy_pass http://mongrel-pt;
  break;
}</pre></div></div>

<p>It was a little tricky to figure out to use the $uri variable. The first rewrite is used for iphone requests so it doesn&#8217;t get the non-iphone cached page.</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2008/01/07/nginx-conf-with-alternate-cache-dir/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>View paths in Rails 2.0</title>
		<link>http://rel.me/2007/12/17/view-paths-in-rails-2-0/</link>
		<comments>http://rel.me/2007/12/17/view-paths-in-rails-2-0/#comments</comments>
		<pubDate>Mon, 17 Dec 2007 17:03:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">/2007/12/17/view-paths-in-rails-2-0</guid>
		<description><![CDATA[New in rails 2.0: ActionController::Base.append_view_path This is useful for loading views from a plugin or gem: ActionController::Base.append_view_path&#40;File.dirname&#40;__FILE__&#41; + &#34;/views&#34;&#41; There is also ActionController::Base.prepend_path.]]></description>
			<content:encoded><![CDATA[<p>New in rails 2.0:</p>
<p><a href="http://api.rubyonrails.org/classes/ActionController/Base.html#M000451">ActionController::Base.append_view_path</a></p>
<p>This is useful for loading views from a plugin or gem:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span class="re2">ActionController::Base</span>.<span class="me1">append_view_path</span><span class="br0">&#40;</span><span class="kw4">File</span>.<span class="me1">dirname</span><span class="br0">&#40;</span><span class="kw2">__FILE__</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot;/views&quot;</span><span class="br0">&#41;</span></pre></div></div>

<p>There is also <a href="http://api.rubyonrails.org/classes/ActionController/Base.html#M000439">ActionController::Base.prepend_path.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/12/17/view-paths-in-rails-2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GC and ObjectSpace</title>
		<link>http://rel.me/2007/08/24/gc-and-objectspace/</link>
		<comments>http://rel.me/2007/08/24/gc-and-objectspace/#comments</comments>
		<pubDate>Fri, 24 Aug 2007 17:01:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[gc]]></category>
		<category><![CDATA[objectspace]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">/2007/09/05/gc-and-objectspace</guid>
		<description><![CDATA[I saw this at the Rails Edge conference and thought it was cool; aside from its really expensive to implement in JRuby. 1 2 3 4 5 6 7 8 9 10 &#62;&#62; GC.disable =&#62; false &#62;&#62; instances = 0 =&#62; 0 &#62;&#62; ObjectSpace.each_object(Artist) { &#124;a&#124; instances += 1 } =&#62; 0 &#62;&#62; Artist.find(:all, :limit [...]]]></description>
			<content:encoded><![CDATA[<p>I saw this at the Rails Edge conference and thought it was cool; aside from its <a href="http://ola-bini.blogspot.com/2007/07/objectspace-to-have-or-not-to-have.html">really expensive to implement in JRuby</a>.</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">&gt;&gt; <span class="co">GC</span>.disable<tt>
</tt>=&gt; <span class="pc">false</span><tt>
</tt>&gt;&gt; instances = <span class="i">0</span><tt>
</tt>=&gt; <span class="i">0</span><tt>
</tt>&gt;&gt;  <span class="co">ObjectSpace</span>.each_object(<span class="co">Artist</span>) { |a| instances += <span class="i">1</span> }<tt>
</tt>=&gt; <span class="i">0</span><tt>
</tt>&gt;&gt; <span class="co">Artist</span>.find(<span class="sy">:all</span>, <span class="sy">:limit</span> =&gt; <span class="i">5</span>)<tt>
</tt>=&gt; [<span class="c">#&lt;Artist:0x327d348 @attributes={....</span><tt>
</tt>&gt;&gt;  <span class="co">ObjectSpace</span>.each_object(<span class="co">Artist</span>) { |a| instances += <span class="i">1</span> }<tt>
</tt>=&gt; <span class="i">5</span></pre>
</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/08/24/gc-and-objectspace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Markup, CSS and Helper cataloging (Part deux)</title>
		<link>http://rel.me/2007/06/25/markup-css-and-helper-cataloging-part-deux/</link>
		<comments>http://rel.me/2007/06/25/markup-css-and-helper-cataloging-part-deux/#comments</comments>
		<pubDate>Mon, 25 Jun 2007 15:37:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[erb]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">/2007/09/03/markup-css-and-helper-cataloging-part-deux</guid>
		<description><![CDATA[I should be using ERB instead of eval. But because you can&#8217;t use &#60;% inside a string block in your view (that I can figure out; &#60;&#60;EOF didn&#8217;t seem to be working in a template). And if you don&#8217;t want to specify the code string in your controller you can use [% ... %]. Here [...]]]></description>
			<content:encoded><![CDATA[<p>I should be using ERB instead of eval. But because you can&#8217;t use &lt;% inside a string block in your view (that I can figure out; &lt;&lt;EOF didn&#8217;t seem to be working in a template). And if you don&#8217;t want to specify the code string in your controller you can use [% ...  %]. Here is the source I am using for our code helper now:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt>15<tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt>22<tt>
</tt>23<tt>
</tt>24<tt>
</tt>25<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  <span class="r">def</span> <span class="fu">erb_code</span>(code) <tt>
</tt>    <span class="co">ERB</span>.new(code).result(binding)    <tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  <span class="r">def</span> <span class="fu">render_code</span>(code, options = {}) <tt>
</tt>    %{ &lt;pre <span class="r">class</span>=<span class="s"><span class="dl">&quot;</span><span class="k">helper</span><span class="dl">&quot;</span></span>&gt;<span class="er">\</span>n&lt;code <span class="r">class</span>=<span class="s"><span class="dl">&quot;</span><span class="k">ruby</span><span class="dl">&quot;</span></span>&gt;<span class="er">\</span>n<span class="c">#{h(code)}\n&lt;/code&gt;\n&lt;/pre&gt; }</span><tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  <span class="r">def</span> <span class="fu">render_markup</span>(html)<tt>
</tt>    doc = <span class="co">REXML</span>::<span class="co">Document</span>.new(html)<tt>
</tt>    markup = <span class="s"><span class="dl">&quot;</span><span class="dl">&quot;</span></span><tt>
</tt>    doc.write(markup, <span class="i">2</span>)<tt>
</tt>    <tt>
</tt>    <span class="s"><span class="dl">%{</span><span class="k"> &lt;pre class=&quot;markup&quot;&gt;</span><span class="ch">\n</span><span class="k">&lt;code class=&quot;html&quot;&gt;</span><span class="ch">\n</span><span class="il"><span class="idl">#{</span>h(markup)<span class="idl">}</span></span><span class="ch">\n</span><span class="k">&lt;/code&gt;</span><span class="ch">\n</span><span class="k">&lt;/pre&gt;</span><span class="ch">\n</span><span class="k"> </span><span class="dl">}</span></span>    <tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  <span class="r">def</span> <span class="fu">render_eval</span>(html)<tt>
</tt>    <span class="s"><span class="dl">%{</span><span class="k"> &lt;div class=&quot;eval&quot;&gt;</span><span class="il"><span class="idl">#{</span>html<span class="idl">}</span></span><span class="k">&lt;/div&gt; </span><span class="dl">}</span></span><tt>
</tt>  <span class="r">end</span><tt>
</tt>    <tt>
</tt>  <span class="r">def</span> <span class="fu">code_helper</span>(code)<tt>
</tt>    code.gsub!(<span class="rx"><span class="dl">/</span><span class="ch">\[</span><span class="k">%</span><span class="dl">/</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">&lt;%</span><span class="dl">&quot;</span></span>).gsub!(<span class="rx"><span class="dl">/</span><span class="k">%</span><span class="ch">\]</span><span class="dl">/</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">%&gt;</span><span class="dl">&quot;</span></span>)    <tt>
</tt>    html = erb_code(code)<tt>
</tt>    render_code(code) + render_markup(html) + render_eval(html)<tt>
</tt>  <span class="r">end</span></pre>
</td>
</tr>
</table>
<p>Then you can do things like:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  &lt;<span class="s"><span class="dl">%=</span><span class="k"> code_helper %{ [%</span><span class="dl">=</span></span> rating_field(<span class="sy">:rating</span>, <span class="sy">:effectiveness</span>) %] } %&gt;</pre>
</td>
</tr>
</table>
<p>and you could also dump it in a helper:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="r">def</span> <span class="fu">code_rating_form_field</span> <tt>
</tt>  &lt;&lt;-<span class="co">EOF</span><tt>
</tt>   &lt;<span class="s"><span class="dl">% </span><span class="k">form_for</span><span class="dl"> </span></span><span class="sy">:rating</span>, <span class="iv">@rating2</span> <span class="r">do</span> |f| <span class="s"><span class="dl">%&gt;</span><span class="k"><tt>
</tt>     &lt;%= f.rating_field(:effectiveness) %</span><span class="dl">&gt;</span></span><tt>
</tt>   &lt;<span class="s"><span class="dl">% </span><span class="k">end</span><span class="dl"> </span></span>%&gt;<tt>
</tt>  <span class="co">EOF</span><tt>
</tt><span class="r">end</span><tt>
</tt><tt>
</tt>  <span class="rx"><span class="dl">/</span><span class="dl">/</span></span> <span class="co">And</span> <span class="r">in</span> your view: &lt;<span class="s"><span class="dl">%=</span><span class="k"> code_helper(code_rating_form_field) %&gt;</span></span></pre>
</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/06/25/markup-css-and-helper-cataloging-part-deux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Network Facade API</title>
		<link>http://rel.me/2007/06/08/network-facade-api/</link>
		<comments>http://rel.me/2007/06/08/network-facade-api/#comments</comments>
		<pubDate>Fri, 08 Jun 2007 03:32:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">/2007/09/03/network-facade-api</guid>
		<description><![CDATA[I was looking at the NetworkFacade api, (check it out at network-facade.rubyforge.org) and noticed: 1 2 3 # Or declate the Foo class and set an uri class Foo &#60; NetworkFacade::Client 'nf://localhost:5042' end where the uri is defined with the Foo declaration. Foo descends from the class returned by the Client class method. 1 2 [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking at the NetworkFacade api, (check it out at <a href="http://network-facade.rubyforge.org/">network-facade.rubyforge.org</a>) and noticed:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  <span class="c"># Or declate the Foo class and set an uri</span><tt>
</tt>  <span class="r">class</span> <span class="cl">Foo</span> &lt; <span class="co">NetworkFacade</span>::<span class="co">Client</span> <span class="s"><span class="dl">'</span><span class="k">nf://localhost:5042</span><span class="dl">'</span></span><tt>
</tt>  <span class="r">end</span></pre>
</td>
</tr>
</table>
<p>where the uri is defined with the Foo declaration. Foo descends from the class returned by the Client class method.</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt>15<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="r">module</span> <span class="cl">NetworkFacade</span><tt>
</tt><tt>
</tt>    <span class="r">def</span> <span class="pc">self</span>.Client(uri = <span class="pc">nil</span>)<tt>
</tt>        <span class="co">TCP</span>::<span class="co">Client</span>.uri = uri<tt>
</tt>        <span class="co">TCP</span>::<span class="co">Client</span><tt>
</tt>    <span class="r">end</span><tt>
</tt><tt>
</tt>    <span class="r">class</span> <span class="cl">Client</span> &lt; <span class="co">TCP</span>::<span class="co">Client</span><tt>
</tt>    <span class="r">end</span><tt>
</tt><tt>
</tt><tt>
</tt>    <span class="r">class</span> <span class="cl">Server</span> &lt; <span class="co">TCP</span>::<span class="co">Server</span><tt>
</tt>    <span class="r">end</span><tt>
</tt><tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>That is cool.</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/06/08/network-facade-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Render content in layout</title>
		<link>http://rel.me/2007/05/30/render-content-in-layout/</link>
		<comments>http://rel.me/2007/05/30/render-content-in-layout/#comments</comments>
		<pubDate>Wed, 30 May 2007 16:35:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">/2007/09/03/render-content-in-layout</guid>
		<description><![CDATA[I came up with a hack to render content inside a layout, from the controller: 1 2 3 4 5 6 7 8 9 10 def content_with_layout(content_for_layout, controller, layout = &#34;the_layout&#34;) locals = { :params =&#62; controller.params } template = controller.class.view_class.new(controller.class.view_root, locals, controller) template.instance_variable_set(&#34;@content_for_layout&#34;, content_for_layout) # This might work to get assigns? untested... #template.assigns = [...]]]></description>
			<content:encoded><![CDATA[<p>I came up with a hack to render content inside a layout, from the controller:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">  <span class="r">def</span> <span class="fu">content_with_layout</span>(content_for_layout, controller, layout = <span class="s"><span class="dl">&quot;</span><span class="k">the_layout</span><span class="dl">&quot;</span></span>)<tt>
</tt>    locals = { <span class="sy">:params</span> =&gt; controller.params }<tt>
</tt>    template = controller.class.view_class.new(controller.class.view_root, locals, controller)<tt>
</tt>    template.instance_variable_set(<span class="s"><span class="dl">&quot;</span><span class="k">@content_for_layout</span><span class="dl">&quot;</span></span>, content_for_layout)    <tt>
</tt>    <tt>
</tt>    <span class="c"># This might work to get assigns? untested...</span><tt>
</tt>    <span class="c">#template.assigns = controller.template.instance_variable_get(&quot;@assigns&quot;) </span><tt>
</tt><tt>
</tt>    template.render_file(<span class="s"><span class="dl">&quot;</span><span class="k">layouts/</span><span class="il"><span class="idl">#{</span>layout<span class="idl">}</span></span><span class="dl">&quot;</span></span>, <span class="pc">true</span>)    <tt>
</tt>  <span class="r">end</span>  </pre>
</td>
</tr>
</table>
<p>You have to pass in any locals you want, and if you want the use assigns in your layout you would have to set the template.assigns. There was some plugin to give you extra layouts in the view but I forget what it was called. Anybody know where that is?</p>
<p><strong>Update:</strong> The inside layout is at: <a href="http://fora.pragprog.com/rails-recipes/write-your-own/post/144">http://fora.pragprog.com/rails-recipes/write-your-own/post/144</a></p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/05/30/render-content-in-layout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rake test task for a custom FileList</title>
		<link>http://rel.me/2007/04/06/rake-test-task-for-a-custom-filelist/</link>
		<comments>http://rel.me/2007/04/06/rake-test-task-for-a-custom-filelist/#comments</comments>
		<pubDate>Fri, 06 Apr 2007 03:32:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Rake]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">/2007/09/03/rake-test-task-for-a-custom-filelist</guid>
		<description><![CDATA[I work on a very large rails project, and rake test has become unruly mostly due to the size of our codebase. Anyway, I wrote this task to run only the tests in the products/namespace I work on. rake test:products PRODUCTS=product1,product2 Runs all unit tests in test/**/product1/*test*.rb, test/**/product2/*test*.rb The task: 1 2 3 4 5 [...]]]></description>
			<content:encoded><![CDATA[<p>I work on a very large rails project, and rake test has become unruly mostly due to the size of our codebase. Anyway, I wrote this task to run only the tests in the products/namespace I work on.</p>
<pre>
rake test:products PRODUCTS=product1,product2
</pre>
<p>Runs all unit tests in test/**/product1/*test*.rb, test/**/product2/*test*.rb</p>
<p>The task:</p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt>15<tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">namespace <span class="sy">:test</span> <span class="r">do</span><tt>
</tt>  task <span class="sy">:products</span> <span class="r">do</span>      <tt>
</tt>    raise <span class="s"><span class="dl">&quot;</span><span class="k">Usage: rake test:products PRODUCTS=product1,product2</span><span class="dl">&quot;</span></span> <span class="r">if</span> <span class="co">ENV</span>[<span class="s"><span class="dl">'</span><span class="k">PRODUCTS</span><span class="dl">'</span></span>].blank?<tt>
</tt>    <tt>
</tt>    products = <span class="co">ENV</span>[<span class="s"><span class="dl">'</span><span class="k">PRODUCTS</span><span class="dl">'</span></span>].split(<span class="rx"><span class="dl">/</span><span class="k">,</span><span class="dl">/</span></span>)<tt>
</tt>    files = []<tt>
</tt>    <tt>
</tt>    products.each <span class="r">do</span> |product|<tt>
</tt>      dir = <span class="s"><span class="dl">&quot;</span><span class="il"><span class="idl">#{</span><span class="co">RAILS_ROOT</span><span class="idl">}</span></span><span class="k">/test/**/</span><span class="il"><span class="idl">#{</span>product<span class="idl">}</span></span><span class="dl">&quot;</span></span><tt>
</tt>      files += <span class="co">FileList</span>[<span class="s"><span class="dl">&quot;</span><span class="il"><span class="idl">#{</span>dir<span class="idl">}</span></span><span class="k">/*test*.rb</span><span class="dl">&quot;</span></span>]<tt>
</tt>    <span class="r">end</span>    <tt>
</tt>    <tt>
</tt>    test_task = <span class="co">Rake</span>::<span class="co">TestTask</span>.new(<span class="s"><span class="dl">&quot;</span><span class="k">test_products</span><span class="dl">&quot;</span></span>) <span class="r">do</span> |t|<tt>
</tt>      t.libs &lt;&lt; <span class="s"><span class="dl">&quot;</span><span class="k">test</span><span class="dl">&quot;</span></span><tt>
</tt>      t.test_files = files<tt>
</tt>      t.verbose = <span class="pc">true</span><tt>
</tt>    <span class="r">end</span><tt>
</tt>    <tt>
</tt>    task(<span class="s"><span class="dl">&quot;</span><span class="k">test_products</span><span class="dl">&quot;</span></span>).execute           <tt>
</tt>  <span class="r">end</span><tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>There is probably an easier way, but this works for me. Also I wouldn&#8217;t mind someone patching rake to accept opts style arguments, like &#8211;opt=blah, or -o blah. The ENV stuff seems really not so friendly.</p>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/04/06/rake-test-task-for-a-custom-filelist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fragment Cache Store with TTL</title>
		<link>http://rel.me/2007/02/21/fragment-cache-store-with-ttl/</link>
		<comments>http://rel.me/2007/02/21/fragment-cache-store-with-ttl/#comments</comments>
		<pubDate>Wed, 21 Feb 2007 05:26:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[railsbench]]></category>

		<guid isPermaLink="false">/2007/09/03/fragment-cache-store-with-ttl</guid>
		<description><![CDATA[I wanted to use a fragment cache, but I didn&#8217;t want to deal with expiring it. So I just made a self-expiring cache based on a TTL. The fragment cache store just wants 4 methods: read, write, delete, delete_matched 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to use a fragment cache, but I didn&#8217;t want to deal with expiring it. So I just made a self-expiring cache based on a TTL.<br/><br />
The fragment cache store just wants 4 methods: <code>read, write, delete, delete_matched</code></p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre>1<tt>
</tt>2<tt>
</tt>3<tt>
</tt>4<tt>
</tt>5<tt>
</tt>6<tt>
</tt>7<tt>
</tt>8<tt>
</tt>9<tt>
</tt><strong>10</strong><tt>
</tt>11<tt>
</tt>12<tt>
</tt>13<tt>
</tt>14<tt>
</tt>15<tt>
</tt>16<tt>
</tt>17<tt>
</tt>18<tt>
</tt>19<tt>
</tt><strong>20</strong><tt>
</tt>21<tt>
</tt>22<tt>
</tt>23<tt>
</tt>24<tt>
</tt>25<tt>
</tt>26<tt>
</tt>27<tt>
</tt>28<tt>
</tt>29<tt>
</tt><strong>30</strong><tt>
</tt>31<tt>
</tt>32<tt>
</tt>33<tt>
</tt>34<tt>
</tt>35<tt>
</tt>36<tt>
</tt>37<tt>
</tt>38<tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="r">class</span> <span class="cl">Cache::MemStore</span><tt>
</tt><tt>
</tt>  attr_reader <span class="sy">:ttl</span>, <span class="sy">:auto_expire</span><tt>
</tt>    <tt>
</tt>  <span class="r">def</span> <span class="fu">initialize</span>(options = {})<tt>
</tt>    <span class="iv">@ttl</span> = options[<span class="sy">:ttl</span>] || <span class="i">10</span>.minutes<tt>
</tt>    <span class="iv">@cache</span> = {}<tt>
</tt>  <span class="r">end</span><tt>
</tt>    <tt>
</tt>  <span class="r">def</span> <span class="fu">expire</span>(pattern)<tt>
</tt>    <span class="iv">@cache</span>.each { |key, val| delete key <span class="r">if</span> key =~ pattern }<tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  <span class="r">def</span> <span class="fu">read</span>(key, options)<tt>
</tt>    delete(key, options) <span class="r">and</span> <span class="r">return</span> <span class="r">if</span> is_expired?(key)<tt>
</tt>    <span class="r">return</span> <span class="iv">@cache</span>[key][<span class="sy">:content</span>] <span class="r">if</span> <span class="iv">@cache</span>.has_key? key<tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  <span class="r">def</span> <span class="fu">write</span>(key, content, options)<tt>
</tt>    <span class="iv">@cache</span>[key] = { <span class="sy">:content</span> =&gt; content, <span class="sy">:created_on</span> =&gt; <span class="co">Time</span>.now }<tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  <span class="r">def</span> <span class="fu">delete_matched</span>(pattern, options)<tt>
</tt>    expire pattern<tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  <span class="r">def</span> <span class="fu">delete</span>(key, options)<tt>
</tt>    <span class="iv">@cache</span>.delete key<tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt>  <span class="r">def</span> <span class="fu">is_expired?</span>(key)<tt>
</tt>    <span class="r">if</span> <span class="iv">@cache</span>.has_key? key<tt>
</tt>      created_on = <span class="iv">@cache</span>[key][<span class="sy">:created_on</span>]<tt>
</tt>      <span class="r">return</span> <span class="co">Time</span>.now &gt; (created_on + <span class="iv">@ttl</span>)<tt>
</tt>    <span class="r">end</span><tt>
</tt>  <span class="r">end</span><tt>
</tt>  <tt>
</tt><span class="r">end</span></pre>
</td>
</tr>
</table>
<p>Then in your <code>environment.rb</code> put: </p>
<table class="CodeRay">
<tr>
<td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }">
<pre><tt>
</tt></pre>
</td>
<td class="code">
<pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"><span class="co">ActionController</span>::<span class="co">Base</span>.fragment_cache_store = <span class="co">Cache</span>::<span class="co">MemStore</span>.new(<span class="sy">:ttl</span> =&gt; <span class="i">10</span>.minutes)</pre>
</td>
</tr>
</table>
<p>railsbench gave me the following results:</p>
<pre>
page request                                      total  stddev%     r/s    ms/r
with cache: /                                   7.23471   2.8012   13.82   72.35
nocache:    /                                  25.81057   0.6966    3.87  258.11
</pre>
]]></content:encoded>
			<wfw:commentRss>http://rel.me/2007/02/21/fragment-cache-store-with-ttl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
