Posted by Chris Blackburn Thu, 18 Jun 2009 21:03:00 GMT

Running RCOV, and having it complain about a p articular plugin that it should not have been looking at in the first place, made me want to find a way to exclude it. In my usual practical fashion, I hit google up for a quick way to exclude the unwanted plugin.

Here it is re-posted from Dan Mange’s Blog

config.plugins = Rails::Initializer.new(config).send(:find_plugins, config.plugin_paths).map {|path| File.basename(path)}
config.plugins -= %W(plugin_one plugin_two)

UPDATE: JJ Barrett has an update for Rails 2.x… http://www.jjbarrett.net/archives/plugin-ordering-and-exclusion-in-rails-20

  config.plugins = config.plugin_locators.map do |locator|
                     locator.new(Rails::Initializer.new(config)).plugins
                   end.flatten.map{|p| p.name.to_sym}
  config.plugins -= [:do_not_load_plugin_1, :do_not_load_plugin_2]

Posted by Chris Blackburn Fri, 29 May 2009 22:23:00 GMT

‘jaap’ wrote a rake task to convert your Rails application from using Gettext translation into the new I18n support, which is really great!

WARNING: Before you run the new rake task rake gettext_to_i18n:transform, read “So How Do You Fix It?” below

OK, so you’ve followed along in the article and now you want to test out your new localization system. Problem is when you try to start the server up script/server you get this error message:

/Users/cblackburn/Source/ruby/bols/lib/active_support/memoizable.rb:71:in `path': can't modify frozen object (TypeError)

…or something similar.

What happened? Since you have frozen Rails and the rake task does not exclude the frozen vendor/rails directory, it modified memoizable.rb in ActiveSupport causing this error.

So How Do You Fix It?

Do one of the following:

  • Backup lib/active_support/memoizable.rb before you run the rake task, then restore it after.
  • Restore lib/active_support/memoizable.rb using your SCM.

For this project in my case it was

svn revert lib/active_support/memoizable.rb

Posted by Chris Blackburn Fri, 29 May 2009 20:49:00 GMT

Another ruby script for your Mac Terminal enjoyment.

I like to work on my Rails projects using at least three command line tabs with their current working directories set to the RAILS_ROOT of my project. This way I can run script/server in one tab, script/console in another and retain one tab to use for various project based work like rake and capistrano tasks. Frequently I found myself manually iterating through each Terminal tab and type ‘cd /Users/…/Source/ruby/projectname’. As we all know personal repetition is the mother of invention. This is what I came up with…

#!/usr/bin/env ruby

require 'rubygems'
require 'appscript'
include Appscript

DEFAULT_PROJ = '.'

project_dir = (ARGV.length > 0) ? ARGV[0] : DEFAULT_PROJ
project_dir = Dir.pwd if project_dir == "."

@term = app('Terminal')
@current_window = @term.windows.first
tab_count = @current_window.tabs.count

for t in 0..tab_count
  tab = @current_window.tabs[t]
  @term.do_script("cd #{project_dir}", :in => tab)
end

Save this file in your personal path as acd.rb

I use this frequently when I switch from one project to another.

Be logged into the directory you want to propagate through all open tabs. Then type: acd.rb which will automatically iterate through each open tab and change the current working directory to the directory you started acd.rb from.