pathspec 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a0eb87d15ea86cb98dce7e2ca41f6939418c3b57
4
+ data.tar.gz: 084dc186f9fbf2f8c4a7ed8268cfa1c78e296728
5
+ SHA512:
6
+ metadata.gz: 17ccc33fba7022b67fe0da1f9c02fbb6bd4e2d6d8e40fcb0d8ed0420f9733ace1692de35e69151e948b788cf007d7ea49f8c1760809ab02b672e61af16aac9e0
7
+ data.tar.gz: a1d2fa238ea0fbc47083c25a4372a6d55848e200b1b850701e63ef12a191c06141b00f0a1871c14b46fe3e8366dcf1dfcf3b588a99f81b2d48117fbefe6eadd5
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
1
  pathspec-ruby
2
2
  =============
3
3
 
4
- Match Path Specifications (.gitignore) in Ruby with ease!
4
+ Match Path Specifications, such as .gitignore, in Ruby!
5
5
 
6
- Gitignore functionality ported from [Python pathspec](https://pypi.python.org/pypi/pathspec/0.2.2) by [@cpburnz](https://github.com/cpburnz/python-path-specification)
6
+ Follows .gitignore syntax defined on [gitscm](http://git-scm.com/docs/gitignore)
7
+
8
+ .gitignore functionality ported from [Python pathspec](https://pypi.python.org/pypi/pathspec/0.2.2) by [@cpburnz](https://github.com/cpburnz/python-path-specification)
9
+
10
+ [Travis Status](https://travis-ci.org/highb/pathspec-ruby) ![Travis CI Status](https://travis-ci.org/highb/pathspec-ruby.svg?branch=master)
7
11
 
8
12
  ## Build/Install from Rubygems
9
13
  ```shell
@@ -32,7 +36,7 @@ gitignore.match 'abc/important.txt'
32
36
  # Give a path somewhere in the filesystem, and the Pathspec will return all
33
37
  # matching files underneath.
34
38
  # Returns ['/src/repo/abc/', '/src/repo/abc/123']
35
- gitignore.match_tree '/src/repo' # ['/src/repo/abc/', '/src/repo/abc/123']
39
+ gitignore.match_tree '/src/repo'
36
40
 
37
41
  # Give an enumerable of paths, and Pathspec will return the ones that match.
38
42
  # Returns ['/abc/123', '/abc/']
@@ -46,4 +50,4 @@ cd pathspec-ruby && bash ./build_from_source.sh
46
50
  ```
47
51
 
48
52
  ## Contributing
49
- Pull requests, bug reports, and feature requests welcome! :smile: I've tried to write exhaustive tests (simplecov 100% coverage, woohoo!) but who knows what cases I've missed.
53
+ Pull requests, bug reports, and feature requests welcome! :smile: I've tried to write exhaustive tests but who knows what cases I've missed.
data/lib/pathspec.rb CHANGED
@@ -35,11 +35,11 @@ class PathSpec
35
35
  # Check if any files in a given directory or subdirectories match the specs
36
36
  # Returns matched paths or nil if no paths matched
37
37
  def match_tree(root)
38
- root = Pathname.new(root)
38
+ rootpath = Pathname.new(root)
39
39
  matching = []
40
40
 
41
41
  Find.find(root) do |path|
42
- relpath = Pathname.new(path).relative_path_from(root).to_s
42
+ relpath = Pathname.new(path).relative_path_from(rootpath).to_s
43
43
  relpath += '/' if File.directory? path
44
44
  if match(relpath)
45
45
  matching << path
@@ -49,14 +49,19 @@ class PathSpec
49
49
  matching
50
50
  end
51
51
 
52
+ def match_path(path, root='/')
53
+ rootpath = Pathname.new(drive_letter_to_path(root))
54
+ relpath = Pathname.new(drive_letter_to_path(path)).relative_path_from(rootpath).to_s
55
+ relpath = relpath + '/' if path[-1].chr == '/'
56
+
57
+ match(relpath)
58
+ end
59
+
52
60
  def match_paths(paths, root='/')
53
- root = Pathname.new(root)
54
61
  matching = []
55
62
 
56
63
  paths.each do |path|
57
- relpath = Pathname.new(path).relative_path_from(root).to_s if root != '/'
58
- relpath = relpath + '/' if path[-1] == '/'
59
- if match(relpath)
64
+ if match_path(path, root)
60
65
  matching << path
61
66
  end
62
67
  end
@@ -64,6 +69,10 @@ class PathSpec
64
69
  matching
65
70
  end
66
71
 
72
+ def drive_letter_to_path(path)
73
+ path.gsub(/^([a-zA-z]):\//, '/\1/')
74
+ end
75
+
67
76
  # Generate specs from a filename, such as a .gitignore
68
77
  def self.from_filename(filename, type=:git)
69
78
  self.from_lines(File.open(filename, 'r'))
@@ -76,6 +76,14 @@ class GitIgnoreSpec < RegexSpec
76
76
  pattern_segs[-1] = '**'
77
77
  end
78
78
 
79
+ # Handle platforms with backslash separated paths
80
+ if File::SEPARATOR == '\\'
81
+ path_sep = '\\\\'
82
+ else
83
+ path_sep = '/'
84
+ end
85
+
86
+
79
87
  # Build regular expression from pattern.
80
88
  regex = '^'
81
89
  need_slash = false
@@ -92,34 +100,34 @@ class GitIgnoreSpec < RegexSpec
92
100
  # A normalized pattern beginning with double-asterisks
93
101
  # ('**') will match any leading path segments.
94
102
  elsif i == 0
95
- regex.concat('(?:.+/)?')
103
+ regex.concat("(?:.+#{path_sep})?")
96
104
  need_slash = false
97
105
 
98
106
  # A normalized pattern ending with double-asterisks ('**')
99
107
  # will match any trailing path segments.
100
108
  elsif i == regex_end
101
- regex.concat('/.*')
109
+ regex.concat("#{path_sep}.*")
102
110
 
103
111
  # A pattern with inner double-asterisks ('**') will match
104
112
  # multiple (or zero) inner path segments.
105
113
  else
106
- regex.concat('(?:/.+)?')
114
+ regex.concat("(?:#{path_sep}.+)?")
107
115
  need_slash = true
108
116
  end
109
117
 
110
118
  # Match single path segment.
111
119
  elsif seg == '*'
112
120
  if need_slash
113
- regex.concat('/')
121
+ regex.concat(path_sep)
114
122
  end
115
123
 
116
- regex.concat('[^/]+')
124
+ regex.concat("[^#{path_sep}]+")
117
125
  need_slash = true
118
126
 
119
127
  else
120
128
  # Match segment glob pattern.
121
129
  if need_slash
122
- regex.concat('/')
130
+ regex.concat(path_sep)
123
131
  end
124
132
 
125
133
  regex.concat(translate_segment_glob(seg))
@@ -155,7 +163,7 @@ class GitIgnoreSpec < RegexSpec
155
163
 
156
164
  while i < pattern.size
157
165
  # Get next character.
158
- char = pattern[i]
166
+ char = pattern[i].chr
159
167
  i += 1
160
168
 
161
169
  # Escape the character.
@@ -187,18 +195,18 @@ class GitIgnoreSpec < RegexSpec
187
195
  elsif char == '['
188
196
  j = i
189
197
  # Pass brack expression negation.
190
- if j < pattern.size && pattern[j] == '!'
198
+ if j < pattern.size && pattern[j].chr == '!'
191
199
  j += 1
192
200
  end
193
201
 
194
202
  # Pass first closing braket if it is at the beginning of the
195
203
  # expression.
196
- if j < pattern.size && pattern[j] == ']'
204
+ if j < pattern.size && pattern[j].chr == ']'
197
205
  j += 1
198
206
  end
199
207
 
200
208
  # Find closing braket. Stop once we reach the end or find it.
201
- while j < pattern.size && pattern[j] != ']'
209
+ while j < pattern.size && pattern[j].chr != ']'
202
210
  j += 1
203
211
  end
204
212
 
@@ -207,7 +215,7 @@ class GitIgnoreSpec < RegexSpec
207
215
  expr = '['
208
216
 
209
217
  # Braket expression needs to be negated.
210
- if pattern[i] == '!'
218
+ if pattern[i].chr == '!'
211
219
  expr += '^'
212
220
  i += 1
213
221
 
@@ -216,13 +224,13 @@ class GitIgnoreSpec < RegexSpec
216
224
  # `fnmatch.translate()` escapes the caret ('^') as a
217
225
  # literal. To maintain consistency with undefined behavior,
218
226
  # I am escaping the '^' as well.
219
- elsif pattern[i] == '^'
227
+ elsif pattern[i].chr == '^'
220
228
  expr += '\\^'
221
229
  i += 1
222
230
  end
223
231
 
224
232
  # Escape brackets contained within pattern
225
- if pattern[i] == ']' && i != j
233
+ if pattern[i].chr == ']' && i != j
226
234
  expr += '\]'
227
235
  i += 1
228
236
  end
metadata CHANGED
@@ -1,87 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brandon High
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-07-24 00:00:00.000000000 Z
11
+ date: 2014-08-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: Use to match path patterns such as gitignore
47
- email:
42
+ email: bh@brandon-high.com
48
43
  executables: []
49
44
  extensions: []
50
45
  extra_rdoc_files: []
51
46
  files:
47
+ - CHANGELOG.md
48
+ - LICENSE
49
+ - README.md
50
+ - lib/pathspec.rb
52
51
  - lib/pathspec/gitignorespec.rb
53
52
  - lib/pathspec/regexspec.rb
54
53
  - lib/pathspec/spec.rb
55
- - lib/pathspec.rb
56
- - LICENSE
57
- - README.md
58
- - CHANGELOG.md
59
- homepage: https://github.com/highb/pathspec-ruby
54
+ homepage: http://rubygems.org/gems/pathspec
60
55
  licenses:
61
56
  - Apache
57
+ metadata: {}
62
58
  post_install_message:
63
59
  rdoc_options: []
64
60
  require_paths:
65
61
  - lib
66
62
  required_ruby_version: !ruby/object:Gem::Requirement
67
- none: false
68
63
  requirements:
69
- - - ! '>='
64
+ - - ">="
70
65
  - !ruby/object:Gem::Version
71
66
  version: '0'
72
- segments:
73
- - 0
74
- hash: 3379845117464924390
75
67
  required_rubygems_version: !ruby/object:Gem::Requirement
76
- none: false
77
68
  requirements:
78
- - - ! '>='
69
+ - - ">="
79
70
  - !ruby/object:Gem::Version
80
71
  version: '0'
81
72
  requirements: []
82
73
  rubyforge_project:
83
- rubygems_version: 1.8.23
74
+ rubygems_version: 2.2.2
84
75
  signing_key:
85
- specification_version: 3
86
- summary: ! 'PathSpec: for matching path patterns'
76
+ specification_version: 4
77
+ summary: 'PathSpec: for matching path patterns'
87
78
  test_files: []