Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
namespace :util do desc "Setup task." task :setup do ## # Requires. require 'rubygems' require 'open-uri' begin require 'hpricot' rescue LoadError raise "ERROR: Task requires hpricot." end ## # Constants HOST = ENV['host'] || "localhost" DOC = Hpricot(open("http://#{HOST}:9090/")) BALANCERS = DOC.search("/html/body/h3/a") NUMBER_OF_BALANCERS = BALANCERS.size end desc "Scrape status of each Mongrel via Load Balancer Manager." task :check_balancers => 'util:setup' do if NUMBER_OF_BALANCERS 2.step(NUMBER_OF_BALANCERS * 2, 2) do |n| 2.step(100, 1) do |i| ### hella lame! status = DOC.search("/html/body/table[#{n}]/tr[#{i}]/td[6]").inner_html break if status.empty? puts DOC.search("/html/body/table[#{n}]/tr[#{i}]/td/a").inner_html + ":" + status end end end end end
This paste will be private.
From the Design Piracy series on my blog: