module InstDataShipper module Hooks extend ActiveSupport::Concern class_methods do def define_hook(name) @hooks ||= {} @hooks[name] ||= [] end def hook(name, prepend: false, &block) hooks = @hooks[name] prepend ? hooks.unshift(block) : hooks << block end end def run_hook(name, *args, **kwargs) hooks = @hooks[name] hooks.each do |blk| instance_exec(*args, **kwargs, &blk) end end def run_hook_safe(name, *args, **kwargs) hooks = @hooks[name] hooks.each do |blk| instance_exec(*args, **kwargs, &blk) rescue StandardError end end end end