Class: Buff::Ignore::IgnoreFile
- Inherits:
-
Object
- Object
- Buff::Ignore::IgnoreFile
- Defined in:
- lib/buff/ignore/ignore_file.rb
Overview
A Ruby representation of an ignore file
Constant Summary collapse
- COMMENT_OR_WHITESPACE =
Regular expression to match comments or plain whitespace
/^\s*(?:#.*)?$/.freeze
Instance Attribute Summary collapse
-
#filepath ⇒ String
readonly
The path to the ignore file.
Instance Method Summary collapse
-
#apply(list) ⇒ Array
Apply the ignore to the list, returning a new list of filtered files.
-
#apply!(list) ⇒ Array?
Destructively remove all files from the given list.
-
#ignored?(filename) ⇒ Boolean
Determine if a given filename should be ignored.
-
#initialize(filepath, options = {}) ⇒ IgnoreFile
constructor
Create a new ignore file from the given filepath.
Constructor Details
#initialize(filepath, options = {}) ⇒ IgnoreFile
Create a new ignore file from the given filepath
27 28 29 30 31 32 |
# File 'lib/buff/ignore/ignore_file.rb', line 27 def initialize(filepath, = {}) @filepath = File.(filepath) @options = raise IgnoreFileNotFound.new(filepath) unless File.exists?(filepath) end |
Instance Attribute Details
#filepath ⇒ String (readonly)
The path to the ignore file
13 14 15 |
# File 'lib/buff/ignore/ignore_file.rb', line 13 def filepath @filepath end |
Instance Method Details
#apply(list) ⇒ Array
Apply the ignore to the list, returning a new list of filtered files
47 48 49 50 51 |
# File 'lib/buff/ignore/ignore_file.rb', line 47 def apply(list) tmp = list.dup apply!(tmp) tmp end |
#apply!(list) ⇒ Array?
Destructively remove all files from the given list
60 61 62 63 64 |
# File 'lib/buff/ignore/ignore_file.rb', line 60 def apply!(list) list.reject! do |item| item.strip.empty? || ignored?(item) end end |
#ignored?(filename) ⇒ Boolean
Determine if a given filename should be ignored
73 74 75 76 77 78 |
# File 'lib/buff/ignore/ignore_file.rb', line 73 def ignored?(filename) base = File.([:base] || File.dirname(filepath)) basename = filename.sub(base + File::SEPARATOR, '') ignores.any? { |ignore| File.fnmatch?(ignore, basename) } end |