Class: RubyCop::GrayList

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

Overview

Combination blacklist and whitelist.

Instance Method Summary collapse

Constructor Details

#initializeGrayList

Returns a new instance of GrayList.



6
7
8
9
# File 'lib/ruby_cop/gray_list.rb', line 6

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)


12
13
14
# File 'lib/ruby_cop/gray_list.rb', line 12

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

#blacklist(item) ⇒ Object



16
17
18
19
# File 'lib/ruby_cop/gray_list.rb', line 16

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

#whitelist(item) ⇒ Object



21
22
23
24
# File 'lib/ruby_cop/gray_list.rb', line 21

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