module JamRuby
  class IpWhitelist< ActiveRecord::Base

    attr_accessible :remote_ip, :notes, as: :admin

    @@log = Logging.logger[IpWhitelist]

    validates :remote_ip, presence:true, uniqueness:true

    def self.listed(remote_ip)
      IpWhitelist.where("remote_ip = '#{remote_ip}'").count == 1
    end

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

    def self.admin_activity_url(remote_ip)
      APP_CONFIG.admin_root_url + "/admin/download_trackers?q[remote_ip_equals]=#{URI.escape(remote_ip)}&commit=Filter&order=id_desc"
    end

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

    def to_s
      remote_ip
    end
  end
end