Created
June 23, 2010 12:41
-
-
Save nicobrevin/449873 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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