class Clockker::WhiteBlackList

Constants

DEFAULT_BLACKLIST

Attributes

blacklist[RW]

blacklist_path should return an array of absolute paths that are to be ignored. Implicitly any path that isn't whitelisted is blacklisted; this method is only useful if it returns subpaths of whitelisted paths. i.e. /Users/paul/Documents is whitelisted, but /Users/paul/Documents/customers/Bell is blacklisted.

url_whitelist[RW]

blacklist_path should return an array of absolute paths that are to be ignored. Implicitly any path that isn't whitelisted is blacklisted; this method is only useful if it returns subpaths of whitelisted paths. i.e. /Users/paul/Documents is whitelisted, but /Users/paul/Documents/customers/Bell is blacklisted.

whitelist[RW]

blacklist_path should return an array of absolute paths that are to be ignored. Implicitly any path that isn't whitelisted is blacklisted; this method is only useful if it returns subpaths of whitelisted paths. i.e. /Users/paul/Documents is whitelisted, but /Users/paul/Documents/customers/Bell is blacklisted.

Public Class Methods

new(clockker_config) click to toggle source
# File lib/clockker/white_black_list.rb, line 21
def initialize(clockker_config)
  @whitelist = []
  @blacklist = []
  @url_whitelist = []

  @whitelist = clockker_config.whitelist.map{|wl| Regexp.new(wl)} if clockker_config.whitelist
  @blacklist = clockker_config.blacklist.map{|bl| Regexp.new(bl)} if clockker_config.blacklist
  @url_whitelist = clockker_config.url_whitelist.map{|uwl| Regexp.new("#{uwl}\/")} if clockker_config.url_whitelist

  # Now set defaults in the absence of a config file
  @whitelist ||= [ Regexp.new(Pathname.new(Dir.home).to_s) ]
  @blacklist ||= [ Regexp.new(Pathname.new(File.join(Dir.home, 'Library')).to_s) ]
  @blacklist += DEFAULT_BLACKLIST.map{|bl| Regexp.new(bl)}
end

Public Instance Methods

ignore?(filepath) click to toggle source
# File lib/clockker/white_black_list.rb, line 36
def ignore?(filepath)
  file_matches_whitelist = @whitelist.any? {|wl| filepath =~ Regexp.new(wl)}
  file_matches_blacklist = @blacklist.any? {|bl| filepath =~ Regexp.new(bl)}
  return true if file_matches_blacklist
  return false if file_matches_whitelist
  return true
end
ignore_url?(url) click to toggle source
# File lib/clockker/white_black_list.rb, line 44
def ignore_url?(url)
  !@url_whitelist.any? {|uwl| url =~ Regexp.new(uwl)}
end