Last active
August 29, 2015 14:09
-
-
Save mikecmpbll/1415ae0202e22bf9168c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ScopeValidators | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def validates(*args) | |
options = args.extract_options! | |
if options.key?(:uniqueness) | |
case options[:uniqueness] | |
when Hash | |
options[:uniqueness].merge!(scope: :entity_id) | |
when TrueClass | |
options[:uniqueness] = { scope: :entity_id } | |
end | |
end | |
super(*args, options) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment