Rails: August 2006 Archives

ruby memory visualizer

| | Comments (3)

I never ever (hardly ever) do graphics, much less GUI apps. So when I do, it is always a chore. But for fun I just whipped up a simple memory visualizer for ruby in less than 100 lines:

ruby memory visualizer [movie]

(key: String = gray, Array = green, Numeric = black (no fixnums), Class = purple, Hash = blue, everything else = red)

This has zero actual value to finding things out, so I will probably not release it.

as seen on IRC

| | Comments (2)
16:05 srbaker : using << self to replace the "duplication" in "def self."
16:05 srbaker : is like using method_missing to remove the duplication of leading a in
16:05 srbaker : apple and aardvark

risearch getting popular

| | Comments (2)

Apparently risearch got folded into ruby-doc.org! How cool is that? Check it out: http://www.ruby-doc.org/risearch/rand. I just made a shortcut in safari (using Stand but you can also use sogudi) so I can type "ri rand" in my url bar and go right to it.

Also note, if you have ruby 1.8 from CVS or the 1.8.5 preview then you also have ri/rubygems integration. This means that looking up rails doco is much more focused and you can now search the rails doco for goodies!

During hacking night last night Eric and I added path independence and searching of gems and local installed ri/rdoc. Enjoy!
#!/usr/local/bin/ruby -w

require 'rdoc/ri/ri_paths'
require 'find'
require 'yaml'

search = ARGV.shift

puts "Searching for #{search}"
puts

dirs = RI::Paths::PATH
dirs.each do |dir|
  Dir.chdir dir do
    Find.find('.') do |path|
      next unless test ?f, path
      yaml = File.read path
      if yaml =~ /#{search}/io then
        full_name = $1 if yaml[/full_name: (.*)/]
        puts "** FOUND IN: #{full_name}"
        
        data = YAML.load yaml.gsub(/ \!.*/, '')
        desc = data['comment'].map { |x| x.values }.flatten.join("\n").gsub(/&quot;/, "'").gsub(/&lt;/, "<").gsub(/&gt;/, ">").gsub(/&amp;/, "&")
        puts
        puts desc
        puts
      end
    end
  end
end

UPDATE: See the latest version.

Check it out. Quick and dirty searching of ri content:

#!/usr/local/bin/ruby -w

require 'find'
require 'yaml'

search = ARGV.shift

puts "Searching for #{search}"
puts

Dir.chdir '/usr/local/share/ri/1.8/system' do
  Find.find('.') do |path|
    next unless test ?f, path
    yaml = File.read path
    if yaml =~ /#{search}/io then
      full_name = $1 if yaml[/full_name: (.*)/]
      puts "** FOUND IN: #{full_name}"
      
      data = YAML.load yaml.gsub(/ \!.*/, '')
      desc = data['comment'].map { |x| x.values }.flatten.join("\n").gsub(/"/, "'").gsub(/</, "<").gsub(/>/, ">").gsub(/&/, "&")
      puts
      puts desc
      puts
    end
  end
end
Lets you do stuff like:
% ./risearch.rb duplicate
Searching for duplicate
[...]
** FOUND IN: Array#uniq!

Removes duplicate elements from self. Returns nil if no changes are made (that is, no duplicates are found).
   a = [ 'a', 'a', 'b', 'b', 'c' ]
   a.uniq!   #=> ['a', 'b', 'c']
   b = [ 'a', 'b', 'c' ]
   b.uniq!   #=> nil

** FOUND IN: Array#|

Set Union---Returns a new array by joining this array with other_array, removing duplicates.
   [ 'a', 'b', 'c' ] | [ 'c', 'd', 'a' ]
          #=> [ 'a', 'b', 'c', 'd' ]
[...]

Upgrade rails now

| | Comments (3)

You need to upgrade rails now. Right now.

If you prefer to freeze your rails checkout. I recommend stealing this rule:

namespace :rails do
  namespace :freeze do
    desc "Lock to a specific rails version. Defaults to 1.1.5 or specify with RELEASE=x.y.z"
    task :version do
      rel = ENV['RELEASE'] || '1.1.5'
      tag = 'rel_' + rel.split(/[.-]/).join('-')
      rails_svn = "http://dev.rubyonrails.org/svn/rails/tags/#{tag}"

      puts "Freezing to #{tag} using #{rails_svn}"
      sh "type svn"
      
      dir = 'vendor/rails'
      rm_rf dir
      mkdir_p dir
      for framework in %w( railties actionpack activerecord actionmailer activesupport actionwebservice )
        checkout = "#{dir}/#{framework}"
        sh "svn export #{rails_svn}/#{framework} #{checkout}"
        unless test ?d, checkout then
          puts "ERROR: checkout missing: #{checkout}"
          exit 1
        end
      end
    end
  end
end

and running:

rake rails:freeze:version

It'll default to 1.1.5 or you can specify the tagged version you want using RELEASE=x.y.z.

using ZenTest on rails

| | Comments (0)

Currently to run zentest on rails you have to jump through some extra hoops. This is because you need to require config/environment to get the magic const loader. BUT, because that maps ClassName to class_name.rb, you also have to load app/controllersapplication.rb (because the class inside is ApplicationController, not Application):

ruby -I.:lib:test -r ./config/environment.rb -r app/controllers/application.rb \
  -S zentest -r app/controllers/groups_controller.rb \
  test/functional/groups_controller_test.rb

I've got some unreleased changes that should make it as easy as:

zentest -r app/controllers/groups_controller.rb \
  test/functional/groups_controller_test.rb

you might just fit here...

| | Comments (0)

From sfbay.craigslist.org:

"The application is built on your classic open source Java stack of Spring and Hibernate running on Tomcat and talking to a MySQL database, so if you haven't yet switched to Ruby, you might just fit in here."

read: if you haven't yet been enlightened, you might not hate your job here...

About this Archive

This page is a archive of entries in the Rails category from August 2006.

Rails: July 2006 is the previous archive.

Rails: September 2006 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Pages

Powered by Movable Type 4.1