require 'pp' Rails.application.config.to_prepare do Model # Zeitwerk autoload model ModelFile # extend by adding listeners class Model attr_accessor :last_action_execution_time # The macro is now run within the context of the existing Model class. after_commit :run_cli_hooks # Define the new method to be executed on save. def run_cli_hooks # Your custom logic to execute after Model.save or Model.update! goes here. now = Time.current rate_limit_seconds = 2.0 last_run_time = @last_action_execution_time if self.path.match('#') if last_run_time.nil? || (now - last_run_time) > rate_limit_seconds self.last_action_execution_time = now # 📝 Example Logic: puts "\n-------- MODEL --------- #{self.id} #{self.path}\n\n" pp self puts "\n\n" command = "TS_SLOTS=5 ts /manyfold/cli/manyfold.sh hook experience_updated #{self.library.path}/#{self.path} &" system(command) end end end end end