Suppose I have a class with a save
method, and three mixins which modify it using aliasing, e.g.
module Callbacks
def save_with_callbacks
callback :before_save
save_without_callbacks
end
end
alias_method_chain :save, :callbacks
end
and similarly for save_with_transaction
and save_with_timestamps
, mixed in in that order, so MyModel#save
calls save_with_timestamps
, which calls save_with_transaction
, which calls save_with_callbacks
, which finally calls the original save
.
Now suppose I want to save without a transaction. I can call save_without_transaction
, but that doesn't call the code to set the timestamps.
How can I save my model with timestamps and callbacks, but no transaction?
I could reorder the mixins, but my question is about omitting the middle, rather than specifically transactions. How can I omit the middle of a chain of methods?
NOTE - I've used RoR's alias_method_chain for brevity, but my question applies to ruby in general