xrforge/manyfold/usr/src/app/config/initializers/xrforge.rb

41 lines
1 KiB
Ruby
Raw Normal View History

2025-10-29 15:05:18 +01:00
require 'pp'
2025-10-29 10:47:55 +01:00
Rails.application.config.to_prepare do
Model # Zeitwerk autoload model
2025-10-29 15:05:18 +01:00
ModelFile
2025-10-29 10:47:55 +01:00
2025-10-29 15:05:18 +01:00
# extend by adding listeners
2025-10-29 10:47:55 +01:00
class Model
2025-10-29 17:57:16 +01:00
attr_accessor :last_action_execution_time
# The macro is now run within the context of the existing Model class.
2025-10-29 15:05:18 +01:00
after_commit :run_cli_hooks
2025-10-29 10:47:55 +01:00
# Define the new method to be executed on save.
2025-10-29 15:05:18 +01:00
def run_cli_hooks
2025-10-29 10:47:55 +01:00
# Your custom logic to execute after Model.save or Model.update! goes here.
2025-10-29 17:57:16 +01:00
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"
2025-10-29 15:05:18 +01:00
2025-10-29 17:57:16 +01:00
command = "TS_SLOTS=5 ts /manyfold/cli/manyfold.sh hook experience_updated #{self.library.path}/#{self.path} &"
system(command)
end
end
2025-10-29 10:47:55 +01:00
end
end
end