Created
January 22, 2011 16:21
-
-
Save amw/791214 to your computer and use it in GitHub Desktop.
This file contains 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 SharedDatabase | |
module UniquenessValidator | |
def self.included(validator) | |
validator.class_eval do | |
def setup_with_subdomain_account(klass) | |
return unless klass.table_exists? | |
if klass.column_names.include? 'subdomain_account_id' | |
scope = [:subdomain_account_id] | |
if defined? @options[:scope] and @options[:scope] | |
if @options[:scope].kind_of? Array | |
scope.push *@options[:scope] | |
else | |
scope.push @options[:scope] | |
end | |
end | |
@options = @options.dup | |
@options[:scope] = scope | |
@options.freeze | |
end | |
setup_without_subdomain_account(klass) | |
end | |
alias_method_chain :setup, :subdomain_account | |
end | |
end | |
end | |
end | |
ActiveRecord::Validations::UniquenessValidator.class_eval do | |
include SharedDatabase::UniquenessValidator | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment