Skip to content

Instantly share code, notes, and snippets.

@benfyvie
benfyvie / object_diagnostics.rb
Created December 22, 2011 17:30 — forked from eric/object_diagnostics.rb
Tools for debugging memory bloat using Ruby's built in ObjectSpace
module ObjectDiagnostics
extend self
#This is handy when you want to determine what types of objects are contributing to memory bloat
#returns the change in object counts since the last time this method was called
def change_in_object_counts
#this will start all counts at 0 for the initial run
@previous_counts ||= Hash.new(0)
@benfyvie
benfyvie / generic_validations.rb
Created June 10, 2011 17:23
automatically add generic validations to all models
module ActiveRecord::Validations::ClassMethods
#inspired by rails-schema_validations
#https://github.com/gregwebs/rails-schema-validations
def add_generic_validations
begin
self.columns.map do |column|
case column.type
when :date
validates_format_of_date(column.name) #this is a custom validation we defined (not part of rails)
end