Class: Clockker::WhiteBlackList

Inherits:
Object
  • Object
show all
Defined in:
lib/clockker/white_black_list.rb

Constant Summary collapse

DEFAULT_BLACKLIST =
[
  "/tmp/",
  "/log/",
  "/logs/",
  "/node_modules/",
  "/dist/",
  "/build/", "/_build/",
  "/private/",
  '\/\..+'  # hide .* files
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clockker_config) ⇒ WhiteBlackList

Returns a new instance of WhiteBlackList.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

Instance Attribute Details

#blacklistObject

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.



8
9
10
# File 'lib/clockker/white_black_list.rb', line 8

def blacklist
  @blacklist
end

#url_whitelistObject

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.



8
9
10
# File 'lib/clockker/white_black_list.rb', line 8

def url_whitelist
  @url_whitelist
end

#whitelistObject

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.



8
9
10
# File 'lib/clockker/white_black_list.rb', line 8

def whitelist
  @whitelist
end

Instance Method Details

#ignore?(filepath) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# 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) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/clockker/white_black_list.rb', line 44

def ignore_url?(url)
  !@url_whitelist.any? {|uwl| url =~ Regexp.new(uwl)}
end