This Is Why Dreamhost Sucks
[eggnog]$ time ./dispatch.fcgi real 2m48.176s user 0m2.090s sys 0m0.550s
And they want me to renew my hosting tomorrow.
Playing Nice with Legacy Data
I was working with a database that had its own rules for pluralization and I wrote a quick hack to try to get ActiveRecord to play nice with their naming conventions. It still crashes and burns a lot, but it’s a work in progress.
module Inflector
def pluralize(word)
if ( word[-1..-1].downcase == 's' ||
word[-1..-2].downcase == 'sh' ||
word[-1..-2].downcase == 'ch' ||
word[-1..-1].downcase == 'x'
)
word << 'es'
elsif word[-1..-1].downcase == 'y'
if ['a', 'e', 'i', 'o', 'u'].include? word[-2..-2]
word << 's'
else
word = word[0..word.length-2] << 'ies'
end
else
word << 's'
end
end
def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
class_name
end
end
class ActiveRecord::Base
class << self
def reset_primary_key #:nodoc:
key = "#{base_class.name}ID"
set_primary_key(key)
key
end
private
def undecorated_table_name(class_name = base_class.name)
table_name = Inflector.pluralize(class_name)
puts table_name
table_name
end
end
end
It still needs a lot of work, but I think it will be pretty cool to get active record to make correct assumptions about table names and keys without explicitly defining them.
Because it's better than text files
So I finally caved and made a blog. I found myself saving code snippets of cool things that I’d picked up in text files on whatever machine I happened to be working on. This brought on a few problems.
First, I am extremely unorganized, and would forget about (and soon after lose forever) the text file containing whatever gem of knowledge I had come across.
Second, a text file saved at work doesn’t help me much at home.
Third (theoretically) someone else out there might have some bizzare desire to read the contents of whatever text file I was in the process of losing.
Thus, this blog was born. I doubt anyone will ever read this, but if it does somehow end up serving a greater good than my personal online sticky note, all the better. Enjoy.