Class: Synchrotron::Ignore
- Inherits:
-
Object
- Object
- Synchrotron::Ignore
- Defined in:
- lib/synchrotron/ignore.rb
Constant Summary collapse
- GLOB_PATTERNS =
{'*' => '.*', '?' => '.'}
- REGEX_COMMENT =
/#.*$/
- REGEX_REGEX =
/^\s*(%r(.).*\2[imxouesn]*)\s*$/i
Instance Method Summary collapse
- #add(list) ⇒ Object
- #add_file(filename) ⇒ Object
-
#initialize(list = [], logger = nil) ⇒ Ignore
constructor
A new instance of Ignore.
- #match(path) ⇒ Object
Constructor Details
#initialize(list = [], logger = nil) ⇒ Ignore
Returns a new instance of Ignore.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/synchrotron/ignore.rb', line 7 def initialize(list = [], logger = nil) @cache = {} @globs = [] @regexes = [] @list = list.to_a @log = logger compile(@list) end |
Instance Method Details
#add(list) ⇒ Object
18 19 20 |
# File 'lib/synchrotron/ignore.rb', line 18 def add(list) compile(list.to_a) end |
#add_file(filename) ⇒ Object
22 23 24 |
# File 'lib/synchrotron/ignore.rb', line 22 def add_file(filename) File.open(filename, 'r') {|f| compile(f.readlines) } end |
#match(path) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/synchrotron/ignore.rb', line 26 def match(path) _path = Synchrotron.relative_path(path.strip) return @cache[_path] if @cache.has_key?(_path) @cache[_path] = match = @globs.any? {|glob| _path =~ glob } || @regexes.any? {|regex| _path =~ regex } @log.verbose "Ignoring #{_path}" if match match end |