daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Sobreescribe el metodo event de acts_as_state_machine para poder agregarle funcionalidad de logger.
  2. module ValidationWatcher
  3.   def self.included(receiver)
  4.     receiver.extend ClassMethods
  5.     receiver.class_eval do
  6.       class << self
  7.         alias_method_chain :validates_uniqueness_of, :watcher
  8.       end
  9.       write_inheritable_attribute :unique_fields, []
  10.       class_inheritable_reader    :unique_fields
  11.     end
  12.   end
  13.   module ClassMethods
  14.     def validates_uniqueness_of_with_watcher(*args)
  15.       read_inheritable_attribute(:unique_fields) << args[0]
  16.       validates_uniqueness_of_without_watcher(args)
  17.     end
  18.   end
  19. end
  20.  
  21. class ActiveRecord::Base
  22.   include ValidationWatcher
  23. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top