Class: Spanx::Whitelist
- Inherits:
-
Object
- Object
- Spanx::Whitelist
- Includes:
- Helper::Exit
- Defined in:
- lib/spanx/whitelist.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#patterns ⇒ Object
Returns the value of attribute patterns.
Instance Method Summary collapse
-
#initialize(filename) ⇒ Whitelist
constructor
A new instance of Whitelist.
- #load_file ⇒ Object
- #match?(line) ⇒ Boolean
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
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'lib/spanx/whitelist.rb', line 6 def filename @filename end |
#patterns ⇒ Object
Returns the value of attribute patterns.
6 7 8 |
# File 'lib/spanx/whitelist.rb', line 6 def patterns @patterns end |
Instance Method Details
#load_file ⇒ Object
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
15 16 17 18 19 |
# File 'lib/spanx/whitelist.rb', line 15 def match?(line) @patterns.any? do |p| p.match(line) end end |