gitattributes 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0a55496d6f14dbe3a2875abf144bb3481abebc5
4
- data.tar.gz: 2deedb0df3e611e6aa5c5d39cba141c8c37fc88f
3
+ metadata.gz: 3391db6ba85e5c53796a1089ca85c426c3a069cd
4
+ data.tar.gz: 4114507b6e91022921434bb96d0568e634986a83
5
5
  SHA512:
6
- metadata.gz: e0e84e35f1e99b4147941e3752e639793d60d44a71b1da514bb4bdf9b07dad7e80da14727fdc7d6845c6e76763a399ab7a62a76b9ff76040756420f2042cf82c
7
- data.tar.gz: 1e3554e0377532cd63ed243973e0ff2d3c9628ad6699d702954e773612905b1f75466960ea6c30292bbd1bb81b11823ebfa3e7768c470556615264a0198b4d96
6
+ metadata.gz: aeda2224f7496f96aa8573c0fc931b913a25b0dba4f906f717b9cdcdac74154862a6947f815e5504a27062ad1880d70f6caee84acedc0e427391a5c881d36d3f
7
+ data.tar.gz: 8033820c58275d628962a675d0423ea6413642419b3c03abc13ab771de752682da8b8ef4d3e4b3aa204432de9c70d75ad9975277596975437a6b1063f2e7a21b
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{gitattributes}
5
- s.version = '2.6.0'
5
+ s.version = '2.7.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
@@ -54,6 +54,20 @@ module Reality #nodoc
54
54
  {}
55
55
  end
56
56
 
57
+ # Returns the rules for the specified path.
58
+ def rules_for_path(path)
59
+ full_path = File.join(@path, path)
60
+
61
+ rules = []
62
+
63
+ self.rules.each do |rule|
64
+ full_pattern = rule.pattern[0] == '/' ? "#{@relative_path}#{rule.pattern}" : "#{@relative_path}/**/#{rule.pattern}"
65
+ rules << rule if File.fnmatch?(full_pattern, full_path, File::FNM_PATHNAME | File::FNM_DOTMATCH)
66
+ end
67
+
68
+ rules
69
+ end
70
+
57
71
  def write_to(filename, options = {})
58
72
  prefix = options[:prefix].nil? ? '' : "#{options[:prefix]}\n"
59
73
  rules = self.rules
@@ -49,6 +49,17 @@ TEXT
49
49
  assert_equal([], attributes.rules.collect {|p| p.to_s})
50
50
  end
51
51
 
52
+ def test_rules_for_path
53
+ attributes = Reality::Git::Attributes.new("#{working_dir}/#{::SecureRandom.hex}")
54
+
55
+ attributes.text_rule('*.md')
56
+ attributes.text_rule('*.rake')
57
+
58
+ assert_equal([], attributes.rules_for_path('Foo.txt').collect {|p| p.to_s})
59
+ assert_equal(['*.md text'], attributes.rules_for_path('Foo.md').collect {|p| p.to_s})
60
+ assert_equal(['*.md text'], attributes.rules_for_path('doc/MyDoc.md').collect {|p| p.to_s})
61
+ end
62
+
52
63
  def test_multiple_rules_with_same_pattern
53
64
  content = <<TEXT
54
65
  * -text
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitattributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Donald