Class: Spanx::Whitelist

Inherits:
Object
  • Object
show all
Includes:
Helper::Exit
Defined in:
lib/spanx/whitelist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::Exit

#error_exit_with_msg, #help_exit

Constructor Details

#initialize(filename) ⇒ Whitelist

Returns a new instance of Whitelist.



8
9
10
11
12
13
# File 'lib/spanx/whitelist.rb', line 8

def initialize(filename)
  @patterns = []
  @filename = filename

  load_file
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/spanx/whitelist.rb', line 6

def filename
  @filename
end

#patternsObject

Returns the value of attribute patterns.



6
7
8
# File 'lib/spanx/whitelist.rb', line 6

def patterns
  @patterns
end

Instance Method Details

#load_fileObject



21
22
23
24
25
26
27
28
29
# File 'lib/spanx/whitelist.rb', line 21

def load_file
  if filename
    begin
      @patterns = ::File.readlines(filename).reject{|line| line =~ /^#/}.map{|p| %r{#{p.chomp()}} }
    rescue Errno::ENOENT
      error_exit_with_msg("Unable to find whitelist file at #{filename}")
    end
  end
end

#match?(line) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/spanx/whitelist.rb', line 15

def match?(line)
  @patterns.any? do |p|
    p.match(line)
  end
end