module EmbedCallbacks::PrependMethods
Public Instance Methods
set_callback(target_method_name, behavior_sym, callback_function_name, **options)
click to toggle source
Calls superclass method
# File lib/embed_callbacks.rb, line 11 def set_callback(target_method_name, behavior_sym, callback_function_name, **options) behavior = Behavior.new(behavior_sym) m = Module.new m.define_method(target_method_name) do |*params| condition = Condition.new(options).call(self) begin method(callback_function_name).call if condition && behavior.before? return_value = super(*params) method(callback_function_name).call if condition && behavior.after? return_value rescue => e method(callback_function_name).call if condition && behavior.rescue? raise e ensure method(callback_function_name).call if condition && behavior.ensure? end end prepend m end