Class: Rubycop::Analyzer::GrayList

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycop/analyzer/gray_list.rb

Overview

Combination blacklist and whitelist.

Instance Method Summary collapse

Constructor Details

#initializeGrayList

Returns a new instance of GrayList.



7
8
9
10
# File 'lib/rubycop/analyzer/gray_list.rb', line 7

def initialize
  @blacklist = Set.new
  @whitelist = Set.new
end

Instance Method Details

#allow?(item) ⇒ Boolean

An item is allowed if it’s whitelisted, or if it’s not blacklisted.

Returns:

  • (Boolean)


13
14
15
# File 'lib/rubycop/analyzer/gray_list.rb', line 13

def allow?(item)
  @whitelist.include?(item) || !@blacklist.include?(item)
end

#blacklist(item) ⇒ Object



17
18
19
20
# File 'lib/rubycop/analyzer/gray_list.rb', line 17

def blacklist(item)
  @whitelist.delete(item)
  @blacklist.add(item)
end

#whitelist(item) ⇒ Object



22
23
24
25
# File 'lib/rubycop/analyzer/gray_list.rb', line 22

def whitelist(item)
  @blacklist.delete(item)
  @whitelist.add(item)
end