wip: initializer
This commit is contained in:
		
							parent
							
								
									e904c0733b
								
							
						
					
					
						commit
						0913b8eab9
					
				
					 1 changed files with 13 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -1,18 +1,26 @@
 | 
			
		|||
require 'pp'
 | 
			
		||||
 | 
			
		||||
Rails.application.config.to_prepare do
 | 
			
		||||
  Model # Zeitwerk autoload model
 | 
			
		||||
  ModelFile
 | 
			
		||||
 | 
			
		||||
  # Reopen the Model class to add new functionality
 | 
			
		||||
  # This must match the name of your ActiveRecord class exactly.
 | 
			
		||||
  # extend by adding listeners 
 | 
			
		||||
  class Model
 | 
			
		||||
    # The 'after_save' macro is now run within the context of the existing Model class.
 | 
			
		||||
    after_save :execute_initializer_after_save
 | 
			
		||||
    after_commit :run_cli_hooks
 | 
			
		||||
 | 
			
		||||
    # Define the new method to be executed on save.
 | 
			
		||||
    def execute_initializer_after_save
 | 
			
		||||
    def run_cli_hooks
 | 
			
		||||
      # Your custom logic to execute after Model.save or Model.update! goes here.
 | 
			
		||||
      
 | 
			
		||||
      # 📝 Example Logic:
 | 
			
		||||
      puts "\n-------- JA --------- #{self.id}\n\n"
 | 
			
		||||
      puts "\n-------- MODEL --------- #{self.id}\n\n"
 | 
			
		||||
      pp self
 | 
			
		||||
      puts "\n\n"
 | 
			
		||||
 | 
			
		||||
      command = "pwd"
 | 
			
		||||
      system(command)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue