Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. module ActiveRecord
  2. module Suppressor
  3. extend ActiveSupport::Concern
  4.  
  5. module ClassMethods
  6. def suppress(&block)
  7. SuppressorRegistry.suppressed[name] = true
  8. yield
  9. ensure
  10. SuppressorRegistry.suppressed[name] = false
  11. end
  12. end
  13.  
  14. # Ignore saving events if we're in suppression mode.
  15. def save!(*args)
  16. SuppressorRegistry.suppressed[self.class.name] ? self : super
  17. end
  18. end
  19.  
  20. class SuppressorRegistry # :nodoc:
  21. extend ActiveSupport::PerThreadRegistry
  22.  
  23. attr_reader :suppressed
  24.  
  25. def initialize
  26. @suppressed = {}
  27. end
  28. end
  29. end
  30.  
  31. module ActiveRecord
  32. class Base
  33. #Other Modules
  34. #..
  35. #..
  36. #..
  37. include Suppressor
  38. end
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement