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 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
- def initialize(filepath)
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.strip.empty? || line.strip =~ COMMENT_OR_WHITESPACE
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
- ignores.any? { |ignore| File.fnmatch?(ignore, filename) }
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
@@ -1,6 +1,6 @@
1
1
  module Buff
2
2
  module Ignore
3
3
  # The version of Buff::Ignore
4
- VERSION = '1.0.3'
4
+ VERSION = '1.0.4'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buff-ignore
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: