Skip to content

Instantly share code, notes, and snippets.

@amw
Created January 22, 2011 16:21
Show Gist options
  • Save amw/791214 to your computer and use it in GitHub Desktop.
Save amw/791214 to your computer and use it in GitHub Desktop.
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