<?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>Codedrop™ Weblog &#187; Rails</title>
	<atom:link href="http://www.codedrop.ca/blog/archives/category/programming/rails/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codedrop.ca/blog</link>
	<description>Drop'n some code and other tech tidbits...</description>
	<lastBuildDate>Mon, 26 Jul 2010 16:45:02 +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>Add some color to your Capistrano scripts</title>
		<link>http://www.codedrop.ca/blog/archives/200</link>
		<comments>http://www.codedrop.ca/blog/archives/200#comments</comments>
		<pubDate>Fri, 27 Nov 2009 23:05:15 +0000</pubDate>
		<dc:creator>groll</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.codedrop.ca/blog/?p=200</guid>
		<description><![CDATA[The beauty of ruby makes it simple to add some colorful syntax highlighting to log messages that are displayed in your capistrano scripts.  Here&#8217;s a chunk of code I added to my utility.rb file that is included by my capfile that performs the magic.

def colorize(text, color_code)
"#{color_code}#{text}\033[0m"
end

def red(text); colorize(text, "\033[31m"); end
def boldred(text); colorize(text, "\033[1;31m"); end
def green(text); [...]]]></description>
			<content:encoded><![CDATA[<p>The beauty of ruby makes it simple to add some colorful syntax highlighting to log messages that are displayed in your capistrano scripts.  Here&#8217;s a chunk of code I added to my utility.rb file that is included by my capfile that performs the magic.</p>
<p><code><br />
def colorize(text, color_code)<br />
"#{color_code}#{text}\033[0m"<br />
end</code><br />
<code><br />
def red(text); colorize(text, "\033[31m"); end<br />
def boldred(text); colorize(text, "\033[1;31m"); end<br />
def green(text); colorize(text, "\033[32m"); end<br />
def boldgreen(text); colorize(text, "\033[1;32m"); end<br />
def yellow(text); colorize(text, "\033[33m"); end<br />
def boldyellow(text); colorize(text, "\033[1;33m"); end<br />
def blue(text); colorize(text, "\033[34m"); end<br />
def boldblue(text); colorize(text, "\033[1;34m"); end<br />
def purple(text); colorize(text, "\033[35m"); end<br />
def boldpurple(text); colorize(text, "\033[1;35m"); end<br />
def cyan(text); colorize(text, "\033[36m"); end<br />
def boldcyan(text); colorize(text, "\033[1;36m"); end<br />
def white(text); colorize(text, "\033[37m"); end<br />
def boldwhite(text); colorize(text, "\033[1;37m"); end<br />
</code><br />
<code><br />
def inform(text); green(text); end<br />
def highlight(text); boldgreen(text); end<br />
def warning(text); yellow(text); end<br />
def alert(text); red(text); end<br />
def section(text); "\n\n#{"*" * 50}\n#{text}\n#{"*" * 50}";<br />
</code><br />
Now by utilizing the wrapper methods like this:<br />
<code><br />
task :testconfig do<br />
logoutputDir = Logging.initialize("#{$deployDir}/logs", $envNameName, $envNameNum)<br />
Logging.info inform("*" * 75)<br />
Logging.info inform(" Starting... ")<br />
Logging.info "      Env: " + highlight('development')<br />
Logging.info "     Date: " + highlight(Time.now.to_s)<br />
Logging.info "     User: " + highlight('jsmith')<br />
Logging.info " Logs Dir: " + highlight('/tmp/projectX/log')<br />
Logging.info inform("*" * 75)<br />
Logging.info inform(".. informational message ...")<br />
Logging.info warning(".. warning message ...")<br />
Logging.info alert(".. alert message ...")<br />
Logging.info highlight(".. highlighted message ..")<br />
Logging.info inform("*" * 75)<br />
Logging.info inform(" Done! ")<br />
Logging.info " Date: " + highlight(Time.now.to_s)<br />
Logging.info " Dist: " + highlight('/tmp/projectX/dist')<br />
Logging.info inform("*" * 75)<br />
end<br />
</code><br />
You'll get pretty output like this:</p>
<div id="attachment_201" class="wp-caption alignnone" style="width: 310px"><a href="http://www.codedrop.ca/blog/wp-content/uploads/2009/11/syntax_highlight.gif"><img class="size-medium wp-image-201" title="syntax_highlight" src="http://www.codedrop.ca/blog/wp-content/uploads/2009/11/syntax_highlight-300x136.gif" alt="Sample console output" width="300" height="136" /></a><p class="wp-caption-text">Sample console output</p></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Add+some+color+to+your+Capistrano+scripts+http://iaadg.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.codedrop.ca/blog/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Add+some+color+to+your+Capistrano+scripts+http://iaadg.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.codedrop.ca/blog/archives/200/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Capistrano Callbacks</title>
		<link>http://www.codedrop.ca/blog/archives/196</link>
		<comments>http://www.codedrop.ca/blog/archives/196#comments</comments>
		<pubDate>Wed, 18 Nov 2009 18:51:10 +0000</pubDate>
		<dc:creator>groll</dc:creator>
				<category><![CDATA[Build Automation]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Capistrano]]></category>

		<guid isPermaLink="false">http://www.codedrop.ca/blog/archives/196</guid>
		<description><![CDATA[Neat way to pre-initalize something in capistrano before a task is run
on :start do  verifyParametersAndInitialize()end
callback options:

 :before, triggered before a task is invoked
 :after, triggered after a task is invoked
 :start, triggered before a top-level task is invoked via the command-line
 :finish, triggered when a top-level task completes
 :load, triggered after all recipes have [...]]]></description>
			<content:encoded><![CDATA[<p>Neat way to pre-initalize something in capistrano before a task is run</p>
<p><code>on :start do<br />  verifyParametersAndInitialize()<br />end</code></p>
<p>callback options:
<ol>
<li> :before, triggered before a task is invoked</li>
<li> :after, triggered after a task is invoked</li>
<li> :start, triggered before a top-level task is invoked via the command-line</li>
<li> :finish, triggered when a top-level task completes</li>
<li> :load, triggered after all recipes have loaded</li>
<li>:exit, triggered after all tasks have completed</li>
</ol>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" alt="" src="http://img.zemanta.com/pixy.gif?x-id=4f2cdfcc-4c28-8945-8c89-a12168624c3b" /></div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Capistrano+Callbacks+http://gz9sp.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.codedrop.ca/blog/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Capistrano+Callbacks+http://gz9sp.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.codedrop.ca/blog/archives/196/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic fields in YAML file.</title>
		<link>http://www.codedrop.ca/blog/archives/68</link>
		<comments>http://www.codedrop.ca/blog/archives/68#comments</comments>
		<pubDate>Mon, 26 Jan 2009 21:30:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.codedrop.ca/blog/?p=68</guid>
		<description><![CDATA[Recently I had the need to setup environment specific .yml files for email configuration.  Normally this goes off without a hitch, however in my case I had the additional requirement of being able to dynamically substitute values in the yml file at runtime.   I thought it would be nice to allow configuration of email to, [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had the need to setup environment specific .yml files for email configuration.  Normally this goes off without a hitch, however in my case I had the additional requirement of being able to dynamically substitute values in the yml file at runtime.   I thought it would be nice to allow configuration of email to, cc, bcc, subject and so forth through the yml file&#8230; thus allowing different environments to target different recipients.  I first tried to access the model from the yml file&#8230;</p>
<p><code><br />
recipient: &lt;%= user.email_address %&gt;<br />
</code></p>
<p>but to no avail.  Seems like the mailer was loaded before the model so the user object was not yet available.  A solution that I came up with, though kind of hacky, was to tokenize the yml with placeholders that are dynamically replaced by the mailer at runtime.</p>
<p>My .yml file now looks like this:</p>
<p><code><br />
email_notifications:<br />
activate:<br />
from: acct_activations@company.com<br />
recipients: @USER_EMAIL@<br />
bcc: devuser@company.com<br />
subject: Activate your new account (@USER_COMPANY@)<br />
</code></p>
<p>and in my mailer I added a method to do the replacement:</p>
<p><code> def replace_yaml_tokens(yaml_doc, user)<br />
yaml_obj = YAML::dump( yaml_doc )<br />
yaml_obj.gsub!(/\@USER_EMAIL\@/, user.email_address)<br />
yaml_obj.gsub!(/\@USER_COMPANY\@/, user.company)<br />
YAML::load( yaml_obj )<br />
end<br />
</code></p>
<p>finally it was a simple call after initializing the mailer to do the replacement.<br />
<code><br />
mailer=replace_yaml_tokens(YAML::load( File.open( "#{RAILS_ROOT}/config/activation.yml" ) )['email_notifications']['activate'], user);<br />
</code></p>
<p>Like I said, maybe not the best solution, but one that worked for me!</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Dynamic+fields+in+YAML+file.+http://pfp6f.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.codedrop.ca/blog/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Dynamic+fields+in+YAML+file.+http://pfp6f.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.codedrop.ca/blog/archives/68/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails rake tests randomly generate ORA-12520 errors.</title>
		<link>http://www.codedrop.ca/blog/archives/58</link>
		<comments>http://www.codedrop.ca/blog/archives/58#comments</comments>
		<pubDate>Mon, 05 Jan 2009 22:07:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.codedrop.ca/blog/?p=58</guid>
		<description><![CDATA[If you find your application randomly throwing &#8220;ORA-12520: TNS:listener could not find available handler for requested type of server&#8221; errors, then try to increase the number of available processes that you have allocated to your Oracle instance.
Logon to
Oracle using sys as sysdba and execute the following:
ALTER SYSTEM SET PROCESSES=150 SCOPE=SPFILE;
After changing the PROCESSES parameter restart [...]]]></description>
			<content:encoded><![CDATA[<p>If you find your application randomly throwing &#8220;ORA-12520: TNS:listener could not find available handler for requested type of server&#8221; errors, then try to increase the number of available processes that you have allocated to your Oracle instance.</p>
<p>Logon to<br />
Oracle using sys as sysdba and execute the following:</p>
<p><code>ALTER SYSTEM SET PROCESSES=150 SCOPE=SPFILE;</code></p>
<p>After changing the PROCESSES parameter restart your Oracle service.  I recently encountered this on a rails project I&#8217;m currently working on with an Oracle XE installation running in a Windows XP VM.  It seems like the default process level was set to 40 so running the rake tests consistently, but sporadically produced these errors at random intervals.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Rails+rake+tests+randomly+generate+ORA-12520+errors.+http://dm3qd.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.codedrop.ca/blog/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Rails+rake+tests+randomly+generate+ORA-12520+errors.+http://dm3qd.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.codedrop.ca/blog/archives/58/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
