Guest User

Untitled

a guest
Jan 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. def _define_before_model_callback(klass, callback) #:nodoc:
  2. klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
  3. def self.before_#{callback}(*args, &block)
  4. set_callback(:#{callback}, :before, *args, &block)
  5. end
  6. CALLBACK
  7. end
  8.  
  9. def _define_around_model_callback(klass, callback) #:nodoc:
  10. klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
  11. def self.around_#{callback}(*args, &block)
  12. set_callback(:#{callback}, :around, *args, &block)
  13. end
  14. CALLBACK
  15. end
  16.  
  17. def _define_after_model_callback(klass, callback) #:nodoc:
  18. klass.class_eval <<-CALLBACK, __FILE__, __LINE__ + 1
  19. def self.after_#{callback}(*args, &block)
  20. options = args.extract_options!
  21. options[:prepend] = true
  22. options[:if] = Array.wrap(options[:if]) << "!halted && value != false"
  23. set_callback(:#{callback}, :after, *(args << options), &block)
  24. end
  25. CALLBACK
  26. end
Add Comment
Please, Sign In to add comment