Skip to content

Instantly share code, notes, and snippets.

@nicobrevin
Created June 23, 2010 12:41
Show Gist options
  • Save nicobrevin/449873 to your computer and use it in GitHub Desktop.
Save nicobrevin/449873 to your computer and use it in GitHub Desktop.
def MyClass
module Transactional
def delete_them
db.delete
end
end
# this looks for a transaction module, introspects the methods,
# adds new methods to MyClass which create transactions and then calls
# it's namesake
include DbRepository
end
module DbRepository
def included(clazz)
clazz.instance_eval do
trx_module = clazz.const_get("Transactional")
trx_module.methods.each {|m| DbRepository.wrap_method(clazz, trx_module, m}
end
end
def wrap_method(target_clazz, trx_module, method_name)
# Adds a method to target clazz which does transaction caretaking
# and then calls method_name on trx_module
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment