buff-ignore 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/lib/buff/ignore/ignore_file.rb +19 -4
- data/lib/buff/ignore/version.rb +1 -1
- metadata +1 -1
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
=========
|
3
|
+
|
4
|
+
v1.0.4
|
5
|
+
------
|
6
|
+
- **Critical Fix** - strip all values before fnmatching
|
7
|
+
- Accept a `:base` argument and only parse relative to the base
|
8
|
+
|
3
9
|
v1.0.3
|
4
10
|
------
|
5
11
|
- Use `#to_s` instead of message for a nicer output to the end-user when an ignore file is not found
|
@@ -19,8 +19,15 @@ module Buff
|
|
19
19
|
#
|
20
20
|
# @param [String, Pathname] filepath
|
21
21
|
# the path to the ignore file
|
22
|
-
|
22
|
+
# @param [Hash] options
|
23
|
+
# a list of options to pass to the ignore file
|
24
|
+
#
|
25
|
+
# @option [#to_s] options :base
|
26
|
+
# the base directory to apply ignores from
|
27
|
+
def initialize(filepath, options = {})
|
23
28
|
@filepath = File.expand_path(filepath)
|
29
|
+
@options = options
|
30
|
+
|
24
31
|
raise IgnoreFileNotFound.new(filepath) unless File.exists?(filepath)
|
25
32
|
end
|
26
33
|
|
@@ -57,12 +64,17 @@ module Buff
|
|
57
64
|
end
|
58
65
|
|
59
66
|
private
|
67
|
+
# The list of options
|
68
|
+
#
|
69
|
+
# @return [Hash]
|
70
|
+
attr_reader :options
|
71
|
+
|
60
72
|
# The parsed contents of the ignore file
|
61
73
|
#
|
62
74
|
# @return [Array]
|
63
75
|
def ignores
|
64
|
-
@ignores ||= File.readlines(filepath).reject do |line|
|
65
|
-
line.
|
76
|
+
@ignores ||= File.readlines(filepath).map(&:strip).reject do |line|
|
77
|
+
line.empty? || line =~ COMMENT_OR_WHITESPACE
|
66
78
|
end
|
67
79
|
end
|
68
80
|
|
@@ -74,7 +86,10 @@ module Buff
|
|
74
86
|
# @return [Boolean]
|
75
87
|
# true if the file should be ignored, false otherwise
|
76
88
|
def ignored?(filename)
|
77
|
-
|
89
|
+
base = File.expand_path(options[:base] || File.dirname(filepath))
|
90
|
+
basename = filename.sub(base + File::SEPARATOR, '')
|
91
|
+
|
92
|
+
ignores.any? { |ignore| File.fnmatch?(ignore, basename) }
|
78
93
|
end
|
79
94
|
end
|
80
95
|
end
|
data/lib/buff/ignore/version.rb
CHANGED