<?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>Dr Nic &#187; Rake</title>
	<atom:link href="http://drnicwilliams.com/category/ruby/rake/feed/" rel="self" type="application/rss+xml" />
	<link>http://drnicwilliams.com</link>
	<description>Ruby makes Rails, Javascript makes Ajax, Dr Nic makes Magic</description>
	<lastBuildDate>Tue, 01 Jun 2010 12:54:18 +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>My attempt at sake task management</title>
		<link>http://drnicwilliams.com/2008/08/19/my-attempt-at-sake-task-management/</link>
		<comments>http://drnicwilliams.com/2008/08/19/my-attempt-at-sake-task-management/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 04:02:11 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Rake]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[TextMate]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/?p=289</guid>
		<description><![CDATA[I&#8217;ve used sake intermittently in my workflow. It competes against me writing helper/admin scripts in my ~/ruby/bin folder. Normally, executable Ruby scripts have won. But I think I have a new solution that could make sake a permanent winner for me. Ruby scripts are easy to create and execute. You just open new file, change [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/' rel='bookmark' title='Permanent Link: Hacking someone&#8217;s gem with github and gemcutter'>Hacking someone&#8217;s gem with github and gemcutter</a> <small> Ever used a rubygem, found a bug, and just...</small></li><li><a href='http://drnicwilliams.com/2008/12/21/migrating-project-websites-to-github-pages-with-sake-tasks-new-websites-with-jekyll_generator/' rel='bookmark' title='Permanent Link: Migrating project websites to github pages with sake tasks, new websites with jekyll_generator'>Migrating project websites to github pages with sake tasks, new websites with jekyll_generator</a> <small> Its almost Christmas time and that means presents. It...</small></li><li><a href='http://drnicwilliams.com/2008/12/11/future-proofing-your-ruby-code/' rel='bookmark' title='Permanent Link: Future proofing your Ruby code. Ruby 1.9.1 is coming.'>Future proofing your Ruby code. Ruby 1.9.1 is coming.</a> <small> Bugger. I&#8217;m a Ruby monogamist. I use the Ruby...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.kitchenzing.com/product.php?pcode=SBB888"><img src='http://www.kitchenzing.com/images/products/SB888-6piecesake.jpg' alt='Sake set' class='alignright' width="200" border="0" /></a></p>
<p>I&#8217;ve used <a href="http://errtheblog.com/posts/60-sake-bomb">sake</a> intermittently in my workflow. It competes against me writing helper/admin scripts in my <code>~/ruby/bin</code> folder. Normally, executable Ruby scripts have won. But I think I have a new solution that could make sake a permanent winner for me.</p>
<p>Ruby scripts are easy to create and execute. You just open new file, change the TextMate grammar to &#8216;Ruby&#8217;, type &#8216;rb&#8217; and press TAB and you&#8217;re off and running (the &#8216;rb&#8217; snippet generates <code>#!/usr/bin/env ruby</code> or a variation of that). You then make the file executable and BAM! you can run the script from any folder in your environment.</p>
<p>Sake tasks are more annoying to write. After creating a new file, you need to create the namespace and task wrappers for your functionality, such as:</p>
<pre>namespace 'foo' do
  namespace 'bar' do
    desc "This task ..."
    task :baz do

    end
  end
end</pre>
<p>Your task isn&#8217;t instantly executable either. After each change, you need to uninstall the task (<code>sake -u foo:bar:baz</code>) and then reinstall the sake file (<code>sake -i foo/bar/baz.sake</code>) and then run it (<code>sake foo:bar:baz</code>). Perhaps there&#8217;s a way to inline edit a sake task, but I can&#8217;t see it from the help options.</p>
<p>But once you&#8217;ve got your script installed in sake, you get all the wonders that sake provides: a named list (with summary) of tasks (<code>sake -T</code>) and the ability to run those tasks anywhere. Ok, that&#8217;s really only one advantage over standard Ruby scripts. But I like it. Oh, namespacing. The <code>baz</code> task exists in a namespace <code>foo:bar</code>. That&#8217;s nice too.</p>
<p>So to make me happy, I need a solution to the dubious &#8220;create-install-execute&#8221; process above. I also want the raw source for all my sake tasks in one place so I can fix/add/change them, reinstall them and move on with my life. I want simple.</p>
<p>So I&#8217;ve forked <a href="http://ozmm.org/">Chris Wanstrath</a>&#8217;s empty <a href="http://github.com/defunkt/sake-tasks/tree/master">sake-tasks</a> repo (<a href="http://github.com/drnic/sake-tasks/tree/master">mine</a>) and added some infrastructure for managing sake tasks. Of course the repo itself is the repository for my sake tasks (which includes a lot from <a href="http://www.lukemelia.com/">Luke Melia</a>), but most importantly it has a single rake task to reinstall all the tasks without any manual fuss.</p>
<p>The rest of this article assumes you want to have your own repository for your own sake tasks hosted on github. This paragraph is probably unnecessary, but I don&#8217;t want to be accused of not being mildly thorough.</p>
<h3 id="fork_the_sake_tasks_repo">Fork the sake-tasks repo</h3>
<p>For thoroughness and a chance to demonstrate some gold-medal git-fu, I&#8217;ll show two ways: fork my repo and forking the original repo from Chris and pulling my stuff into yours. It&#8217;s git, it&#8217;s distributed, you can do anything.</p>
<p>If you want to fork my repo and skip a nifty git lesson, go to my <a href="http://github.com/drnic/sake-tasks/tree/master">sake-tasks</a> repo and click &#8220;fork&#8221;. Then follow the clone instructions as you normally do when you are blatantly, systematically duplicating someone else&#8217;s hard work, using a command that will look something like:</p>
<pre>git clone git@github.com:your-github-username/sake-tasks.git</pre>
<p>Now, lazy man, you can skip to the next step.</p>
<p>If you want to flex your git-fu, then go and fork Chris&#8217; <a href="http://github.com/defunkt/sake-tasks/tree/master">repo</a> instead. Again, follow the clone instructions. </p>
<p><img src="http://img.skitch.com/20080819-x6k16gsb4axearp6g5if6ntxs2.jpg" alt="empty repo from defunkt"/></p>
<p>Now take a moment to reflect on just how empty your repository is. A fine moment in open-source where you&#8217;ve essentially cloned an empty repository. Hardly worth the effort, but since Chris is a creator of github then if he creates an empty repository then who am I to disagree. Empty it shall start. </p>
<p>Now let&#8217;s pull in the code and tasks from my repo. My repo could be any git repo anywhere on the tubes. </p>
<p><a href="http://drnicwilliams.com/2008/02/03/using-git-within-a-team/">One way</a> you could pull my code into your local repository is to add my repo as a remote and then pull in the goodness:</p>
<pre>git remote add drnic git://github.com/drnic/sake-tasks.git
git pull drnic master</pre>
<p>This is useful if you ever plan on re-pulling from a target repo again in the future.</p>
<p>If you just want to pull from someone&#8217;s repo one time only, then you can merge these two lines together:</p>
<pre>git pull git://github.com/drnic/sake-tasks.git master</pre>
<p>If you get occasional pull requests for your projects, then the latter option is handy to know.</p>
<p>Your local repo is now different to your remote repo (your fork on github) so push it back to your remote:</p>
<pre>git push origin master</pre>
<h3 id="installing_the_sake_tasks">Installing the sake tasks</h3>
<p>I originally created my sake-tasks fork so I could store a <a href="http://github.com/drnic/sake-tasks/tree/master/git/manpages/install.sake">git:manpages:install</a> task. I&#8217;ve just upgraded to git 1.6 (note to self: I want an &#8216;upgrade to latest git version via src&#8217; task; <strong>UPDATE</strong> the repository now includes a <code>git:src:install</code> task to do this) and found some <a href="http://subtlegradient.com/articles/2008/02/21/install_git_leopard">instructions</a> for installing the pre-built manpages. Then I got over excited and refactored all of Luke Melia&#8217;s git+mysql+ssh tasks in to my repo so it looked like I&#8217;d done a lot of work.</p>
<p>To install all the tasks, first install sake:</p>
<pre>sudo gem install sake</pre>
<p>Then run the install task (check below for the list of tasks to be installed):</p>
<p>WARNING: This will uninstall any tasks you already have by the same name.</p>
<pre>rake install</pre>
<p>Now, check that your sake tasks are installed:</p>
<pre>sake -T</pre>
<p>Gives you:</p>
<pre>sake git:analyze:commits:flog_frequent   # Flog the most commonly revised files in the git history
sake git:close                           # Delete the current branch and switch back to master
sake git:manpages:install                # Install man pages for current git version
sake git:open                            # Create a new branch off master
sake git:pull                            # Pull new commits from the repository
sake git:push                            # Push all changes to the repository
sake git:status                          # Show the current status of the checkout
sake git:topic                           # Create a new topic branch
sake git:update                          # Pull new commits from the repository
sake mysql:dump                          # Dump the database to FILE (depends on mysql:params)
sake mysql:load                          # Load the database from FILE (depends on mysql:params)
sake ssh:install_public_key              # Install your public key on a remote server.</pre>
<p>Sexy.</p>
<h3 id="adding_new_recipes_tasks">Adding new recipes/tasks</h3>
<p>The installer rake task rake install works by assuming that each .sake file contains one sake task. This allows the rake task to uninstall the tasks from sake first, and then re-install it (sake barfs if you attempt to reinstall an existing task). Without the one-task-per-file rule, the solution would be to load all the sake tasks as rake tasks into memory. But I like one-task-per-file; it seems clean.</p>
<p>So, to create a task <code>foo:bar:baz</code>, you&#8217;ll need to add a folder <code>foo/bar</code> and create a file <code>baz.sake</code> inside it. Within that file you would then specify your task using namespace and task method calls:</p>
<pre>namespace 'foo' do
  namespace 'bar' do
    desc "This task ..."
    task :baz do

    end
  end
end
</pre>
<p>To install new tasks or reinstall modified tasks, just run the rake task (<code>rake install</code> or <code>rake</code>).</p>
<h4 id="textmate_users">TextMate users</h4>
<p>The latest <a href="http://github.com/drnic/ruby-tmbundle">Ruby.tmbundle</a> on github includes a task command that generates the above namespace/task snippet based on the path + file name. That is, inside the foo/bar/baz.sake file, make sure your grammar is &#8216;Ruby&#8217; or &#8216;Ruby on Rails&#8217; and then type &#8220;task&#8221; and press TAB. The above snippet will be generated ready for you to specify your task.</p>
<h3 id="summary">Summary</h3>
<p>So now I have a single place for all my original sake source and a simple rake task to re-install the tasks if I add or modify them. And because its all in one git repo, if other people fork it and add their own tasks then I can steal them.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2009/11/04/hacking-someones-gem-with-github-and-gemcutter/' rel='bookmark' title='Permanent Link: Hacking someone&#8217;s gem with github and gemcutter'>Hacking someone&#8217;s gem with github and gemcutter</a> <small> Ever used a rubygem, found a bug, and just...</small></li><li><a href='http://drnicwilliams.com/2008/12/21/migrating-project-websites-to-github-pages-with-sake-tasks-new-websites-with-jekyll_generator/' rel='bookmark' title='Permanent Link: Migrating project websites to github pages with sake tasks, new websites with jekyll_generator'>Migrating project websites to github pages with sake tasks, new websites with jekyll_generator</a> <small> Its almost Christmas time and that means presents. It...</small></li><li><a href='http://drnicwilliams.com/2008/12/11/future-proofing-your-ruby-code/' rel='bookmark' title='Permanent Link: Future proofing your Ruby code. Ruby 1.9.1 is coming.'>Future proofing your Ruby code. Ruby 1.9.1 is coming.</a> <small> Bugger. I&#8217;m a Ruby monogamist. I use the Ruby...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2008/08/19/my-attempt-at-sake-task-management/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Pastie paradise</title>
		<link>http://drnicwilliams.com/2007/06/28/pastie-paradise/</link>
		<comments>http://drnicwilliams.com/2007/06/28/pastie-paradise/#comments</comments>
		<pubDate>Thu, 28 Jun 2007 07:27:37 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Rake]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/2007/06/28/pastie-paradise/</guid>
		<description><![CDATA[Summary: click to select Ever tried emailing someone a chunk of code? Some program output? It starts in the default font, then you change it to a fix-width font, but you still don&#8217;t have any syntax highlighting; and the end user has no easy way to extract it from their email and reuse it. Oh, [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2008/08/19/my-attempt-at-sake-task-management/' rel='bookmark' title='Permanent Link: My attempt at sake task management'>My attempt at sake task management</a> <small> I&#8217;ve used sake intermittently in my workflow. It competes...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p id="bk_summary_198" name="bk_summary_198" class="bk_summary"><strong>Summary: </strong> <span class="help">click to select</span></p>
<input id="bk_summary_input_198" value="Pastie make the it easier to share code/output" style="width:100%"  onClick="javascript:var summary = document.getElementById('bk_summary_input_198'); summary.focus();summary.select();" readonly="true" /></span></p>
<p>Ever tried emailing someone a chunk of code? Some program output?</p>
<p>It starts in the default font, then you change it to a fix-width font, but you still don&#8217;t have any syntax highlighting; and the end user has no easy way to extract it from their email and reuse it.</p>
<p>Oh, how about sharing chunks of text/code/program output via Skype/GoogleTalk where the IM makes no effort what-so-ever to keep your pasted text nicely formatted.</p>
<p>Or, <span class="caps">IRC</span>, where its definitely poor form to paste in multi-line chunks of anything. Plus it looks ugly and is completely non-reusable.</p>
<p><a class="imagelink" href="http://drnicwilliams.com/wp-content/uploads/2007/06/pastie.png" title="Pastie"><img id="image199" src="http://drnicwilliams.com/wp-content/uploads/2007/06/pastie.png" alt="Pastie" /></a></p>
<p>The solution is to store the chunk somewhere else (website) and forward that (url) to all and sundry.</p>
<p>The solution is <a href="http://pastie.caboo.se/">pastie</a> (or <a href="http://pastie.textmate.org">TextMate pastie</a> or other pastie services), by <a href="http://www.workingwithrails.com/person/5337-josh-goebel">Josh Goebel</a></p>
<h3>How to use?</h3>
<p>Hands up if you&#8217;ve never driven in a car and used its seatbelts.</p>
<p>Ok, then why does every airline around the world show you how to use one?</p>
<p>Right. So, I&#8217;m not going to show you how to use pastie. Its a form and a submit button.</p>
<h3>Moving on&#8230;</h3>
<p>The other day, <a href="http://errtheblog.com/">Chris Wanstrath</a>, took another step closer to becoming a Deity for Novel Helper Apps, with the release of <a href="http://errtheblog.com/post/6069">sake</a> &#8211; the system-wide Rake tool. A tremendous way to access Ruby code (coded as Rake tasks) from anywhere, without polluting your path, or requiring you to bundle the code as a RubyGem to share it easily.</p>
<p>What does this have to do with pasties?</p>
<p>There is a sake task for sending anything to pastie. Cop a look&#8230;</p>
<pre>
# sake 1.0.6 available now
gem install sake -y
sake -i http://pastie.caboo.se/73801.txt
sake -T
sake pastie:send
  # Sends STDIN or FILE=file to Pastie;
  # USAGE: cat some_code.rb | sake pastie:send
  # OR:    sake pastie:send FILE=some_code.rb
</pre>
<p>On <span class="caps">OSX</span>, you can get the url for your new pastie in the clipboard using <code>pbcopy</code>:</p>
<pre>cat some_code.rb | sake pastie:send | pbcopy</pre>
<p>Want to send a patch to someone via pastie?</p>
<pre>svn diff | sake pastie:send | pbcopy</pre>
<p>and the pastie url is now in your clipboard ready to paste in trac/irc/email, etc.</p>
<h3>Pastie-ing sake tasks</h3>
<p>Theoretically, you could send someone your beloved sake tasks with:</p>
<pre>sake -e my_task | sake pastie:send | pbcopy</pre>
<p>As of sake 1.0.6, you can use the <code>-P</code> option instead:</p>
<pre>sake -P my_task | pbcopy</pre>
<h3>Coming from the future</h3>
<p>Rumour has it, (because Chris told me) that <a href="http://errtheblog.com">Chris and PJ</a> are building an app to take pastie-ing to the next level.</p>
<p>I&#8217;m guessing the magic formula will be:</p>
<ol>
<li>Create a pastie clone</li>
<li>Add social networking</li>
<li>Add versioning of pasties</li>
<li>Write wicked-cool blog post and link the whole store to a dubious personal trait, such as drinking sake and beer at the same time</li>
<li>Watch their Working With Rails <a href="http://www.workingwithrails.com/browse/popular/people">popularity</a> rankings climb (see <a href="http://www.workingwithrails.com/person/5241-chris-wanstrath">Chris</a> and <a href="http://www.workingwithrails.com/person/7015-pj-hyett">PJ</a>)</li>
</ol>
<h3>Bonus &#8211; Railscast competition</h3>
<p>I love the <a href="http://railscasts.com/">Railscast</a> videos, by <a href="http://www.workingwithrails.com/person/6491-ryan-bates">Ryan Bates</a>. Short video chunks of Rails/Ruby goodness.</p>
<p>To motivate people to submit Rails Documentation Patches he&#8217;s now running a <a href="http://railscasts.com/contest">competition</a> with prizes!</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2008/08/19/my-attempt-at-sake-task-management/' rel='bookmark' title='Permanent Link: My attempt at sake task management'>My attempt at sake task management</a> <small> I&#8217;ve used sake intermittently in my workflow. It competes...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2007/06/28/pastie-paradise/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Capistrano variables</title>
		<link>http://drnicwilliams.com/2007/04/10/capistrano-variables/</link>
		<comments>http://drnicwilliams.com/2007/04/10/capistrano-variables/#comments</comments>
		<pubDate>Tue, 10 Apr 2007 20:20:44 +0000</pubDate>
		<dc:creator>Dr Nic</dc:creator>
				<category><![CDATA[Rake]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://drnicwilliams.com/2007/04/10/capistrano-variables/</guid>
		<description><![CDATA[Here&#8217;s an example of how you can pass variables to your capistrano actions via the cap command. desc "Returns last lines of log file. Usage: cap log [-s lines=100] [-s rails_env=production]" task :log do lines = configuration.variables[:lines] &#124;&#124; 100 rails_env = configuration.variables[:rails_env] &#124;&#124; 'production' run "tail -n #{lines} #{app_dir}/log/#{rails_env}.log" do &#124;ch, stream, out&#124; puts out [...]


Related posts:<ol><li><a href='http://drnicwilliams.com/2007/04/12/magic-multi-connections-a-facility-in-rails-to-talk-to-more-than-one-database-at-a-time/' rel='bookmark' title='Permanent Link: Magic Multi-Connections: A &#8220;facility in Rails to talk to more than one database at a time&#8221;'>Magic Multi-Connections: A &#8220;facility in Rails to talk to more than one database at a time&#8221;</a> <small>At this point in time there’s no facility in Rails...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s an example of how you can pass variables to your capistrano actions via the <code>cap</code> command.</p>
<textarea name="code" class="ruby" cols="60" rows="10">
desc "Returns last lines of log file. Usage: cap log [-s lines=100] [-s rails_env=production]"
task :log do
  lines     = configuration.variables[:lines] || 100
  rails_env = configuration.variables[:rails_env] || 'production'
  run "tail -n #{lines} #{app_dir}/log/#{rails_env}.log" do |ch, stream, out|
    puts out
  end
end
</textarea>
<p>So, the above action could be called as follows:</p>
<pre>
cap log
cap log -s lines=1000
cap log -s rails_env=test
</pre>
<p>For reference, you pass values to Rake tasks via environment variables:</p>
<pre>
rake db:migrate RAILS_ENV=test
</pre>
<p>Inside the db:migrate task, you&#8217;d retrieve the value &#8216;test&#8217; via <code>ENV['RAILS_ENV'].</p>
<p>And further more, this then compares to how you'd normally pass option values into normal command-line apps:</p>
<pre>
tail -n 1000 log/production.log
</pre>
<p>Who said the unix command line wasn't easy peasy. Bah.</p>


<p>Related posts:<ol><li><a href='http://drnicwilliams.com/2007/04/12/magic-multi-connections-a-facility-in-rails-to-talk-to-more-than-one-database-at-a-time/' rel='bookmark' title='Permanent Link: Magic Multi-Connections: A &#8220;facility in Rails to talk to more than one database at a time&#8221;'>Magic Multi-Connections: A &#8220;facility in Rails to talk to more than one database at a time&#8221;</a> <small>At this point in time there’s no facility in Rails...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://drnicwilliams.com/2007/04/10/capistrano-variables/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
