module JamRuby
  class EmailBlacklist < ActiveRecord::Base

    attr_accessible :email, :source, :notes, as: :admin

    @@log = Logging.logger[EmailBlacklist]

    validates :email, uniqueness: true

    def self.banned(user)
      EmailBlacklist.where("email = '#{user.email.downcase}'").count >= 1
    end

    def self.listed(user)
      EmailBlacklist.where("email = '#{user.id}'").count == 1
    end

    def self.admin_url
      APP_CONFIG.admin_root_url + "/admin/email_blacklists/"
    end

    def admin_url
      APP_CONFIG.admin_root_url + "/admin/email_blacklists/" + id
    end

    def to_s
      user
    end
  end
end
