<?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>Depois eu leio &#187; rails</title>
	<atom:link href="http://depoiseuleio.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://depoiseuleio.com</link>
	<description></description>
	<lastBuildDate>Fri, 13 Aug 2010 11:38:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Refatorando arquivos de configuração</title>
		<link>http://depoiseuleio.com/2010/05/08/refatorando-arquivos-de-configuracao/</link>
		<comments>http://depoiseuleio.com/2010/05/08/refatorando-arquivos-de-configuracao/#comments</comments>
		<pubDate>Sat, 08 May 2010 17:36:35 +0000</pubDate>
		<dc:creator>rogerio</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://depoiseuleio.com/?p=74</guid>
		<description><![CDATA[Para reduzir a quantidade de linhas repetidas em arquivos yml, é possível reutilizar blocos. Por exemplo, este arquivo de configuração padrão... development: adapter: mysql database: my_project_development username: root password: 123 &#160; test: adapter: mysql database: my_project_test username: root password: 123 &#160; production: adapter: mysql database: my_project_production username: root password: 123 ...pode ser refatorado assim: shared: [...]]]></description>
			<content:encoded><![CDATA[<p>Para reduzir a quantidade de linhas repetidas em arquivos yml, é possível reutilizar blocos. Por exemplo, este arquivo de configuração padrão...</p>
<pre class="ruby">development:
  adapter: mysql
  database: my_project_development
  username: root
  password: <span style="color:#006666;">123</span>
&nbsp;
test:
  adapter: mysql
  database: my_project_test
  username: root
  password: <span style="color:#006666;">123</span>
&nbsp;
production:
  adapter: mysql
  database: my_project_production
  username: root
  password: <span style="color:#006666;">123</span></pre>
<p>...pode ser refatorado assim:</p>
<pre class="ruby">shared: &amp;shared
  adapter: mysql
  username: root
  password: <span style="color:#006666;">123</span>
&nbsp;
development:
  &lt;&lt;: *shared
  database: my_project_development
&nbsp;
test:
  &lt;&lt;: *shared
  database: my_project_test
&nbsp;
production:
  &lt;&lt;: *shared
  database: my_project_production
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://depoiseuleio.com/2010/05/08/refatorando-arquivos-de-configuracao/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pesquisar e alterar um valor no Hash</title>
		<link>http://depoiseuleio.com/2010/05/05/pesquisar-e-alterar-um-valor-no-hash/</link>
		<comments>http://depoiseuleio.com/2010/05/05/pesquisar-e-alterar-um-valor-no-hash/#comments</comments>
		<pubDate>Wed, 05 May 2010 12:18:34 +0000</pubDate>
		<dc:creator>rogerio</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://depoiseuleio.com/?p=62</guid>
		<description><![CDATA[Esses dias precisei procurar e alterar um valor específico num Hash, por exemplo: &#160; my_hash = &#123;:key1 =&#62; &#34;value1&#34;, :key2 =&#62; &#34;value2&#34;, &#91;&#123;:key3 =&#62; &#34;target_value&#34;&#125;&#93;&#125; &#160; Como a classe Hash não oferece busca recursiva por padrão, podemos abri-la e adicionar nosso próprio método. &#160; class Hash def swap_value&#40;target_value, new_value&#41; self.each do &#124;k, v&#124; case v [...]]]></description>
			<content:encoded><![CDATA[<p>Esses dias precisei procurar e alterar um valor específico num Hash, por exemplo:</p>
<pre class="ruby">&nbsp;
my_hash = <span style="color:#006600; font-weight:bold;">&#123;</span>:key1 =&gt; <span style="color:#996600;">&quot;value1&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:key2</span> =&gt; <span style="color:#996600;">&quot;value2&quot;</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#123;</span>:key3 =&gt; <span style="color:#996600;">&quot;target_value&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;</pre>
<p>Como a classe Hash não oferece busca recursiva por padrão, podemos abri-la e adicionar nosso próprio método.</p>
<pre class="ruby">&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">Hash</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> swap_value<span style="color:#006600; font-weight:bold;">&#40;</span>target_value, new_value<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> |k, v|
      <span style="color:#9966CC; font-weight:bold;">case</span> v
        <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#CC0066; font-weight:bold;">String</span>
          <span style="color:#0000FF; font-weight:bold;">self</span><span style="color:#006600; font-weight:bold;">&#91;</span>k<span style="color:#006600; font-weight:bold;">&#93;</span> = new_value <span style="color:#9966CC; font-weight:bold;">if</span> v == target_value
        <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#CC0066; font-weight:bold;">Array</span>
          v.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span>|item| item.<span style="color:#9900CC;">swap_value</span><span style="color:#006600; font-weight:bold;">&#40;</span>target_value, new_value<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
        <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#CC00FF; font-weight:bold;">Hash</span>
          v.<span style="color:#9900CC;">swap_value</span><span style="color:#006600; font-weight:bold;">&#40;</span>target_value, new_value<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;</pre>
<p>É isso, agora a classe Hash tem um método para <em>find and replace</em> recursivo.</p>
<pre class="ruby">&nbsp;
my_hash.<span style="color:#9900CC;">swap_value</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;target_value&quot;</span>, <span style="color:#996600;">&quot;my_new_value&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://depoiseuleio.com/2010/05/05/pesquisar-e-alterar-um-valor-no-hash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I18N + datetime_select = erro “can&#8217;t convert Symbol into String”</title>
		<link>http://depoiseuleio.com/2009/04/11/i18n-datetime_select-erro-cant-convert-symbol-into-string/</link>
		<comments>http://depoiseuleio.com/2009/04/11/i18n-datetime_select-erro-cant-convert-symbol-into-string/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 02:24:34 +0000</pubDate>
		<dc:creator>rogerio</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://depoiseuleio.com/2009/04/11/i18n-datetime_select-erro-cant-convert-symbol-into-string/</guid>
		<description><![CDATA[Não acontece se especificar a ordem: &#60;%= f.datetime_select :date_of_birth, rder =&#62; [:year, :month, :day] %&#62;]]></description>
			<content:encoded><![CDATA[<p>Não acontece se especificar a ordem:</p>
<p><strong>&lt;%= f.datetime_select :date_of_birth, <img src='http://depoiseuleio.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder =&gt; [:year, :month, :day] %&gt;</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://depoiseuleio.com/2009/04/11/i18n-datetime_select-erro-cant-convert-symbol-into-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rake temperamental com Mysql no Vista</title>
		<link>http://depoiseuleio.com/2009/04/11/rake-temperamental-com-mysql-no-vista/</link>
		<comments>http://depoiseuleio.com/2009/04/11/rake-temperamental-com-mysql-no-vista/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 18:15:14 +0000</pubDate>
		<dc:creator>rogerio</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://depoiseuleio.com/?p=11</guid>
		<description><![CDATA[Configurar o Rails pra rodar no Windows Vista não foi de primeira. Depois de uma briga com o RubyGems porque não tinha configurado a variável de ambiente GEM_PATH, o rake que ficou temperamental e sempre dava a seguinte mensagem: rake aborted! Mysql::Error: Commands out of sync; you can't run this command now: SHOW TABLES Pra [...]]]></description>
			<content:encoded><![CDATA[<p>Configurar o Rails pra rodar no Windows Vista não foi de primeira. Depois de uma briga com o RubyGems porque não tinha configurado a variável de ambiente GEM_PATH, o rake que ficou temperamental e sempre dava a seguinte mensagem:</p>
<p><strong>rake aborted!<br />
Mysql::Error: Commands out of sync; you can't run this command now: SHOW TABLES</strong></p>
<p>Pra corrigir: precisa adicionar ao diretório C:\ruby\bin a DLL libmysql.dll. Achei a resposta <a href="http://forums.aptana.com/viewtopic.php?f=20&amp;t=8271" target="_blank">aqui</a>, e pra minha sorte eu também tinha o Wamp instalado com uma versão da DLL.</p>
<p>Ctrl+C –&gt; Ctrl+V, rake feliz.</p>
]]></content:encoded>
			<wfw:commentRss>http://depoiseuleio.com/2009/04/11/rake-temperamental-com-mysql-no-vista/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
