globby 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -1
- data/lib/globby/glob.rb +5 -4
- data/spec/gitignore_spec.rb +15 -6
- data/spec/globby_spec.rb +15 -17
- metadata +10 -12
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b9f9316d279400e594fa7fb870e1d34cad379c42
|
4
|
+
data.tar.gz: f6a17b74c29c236adb60637fb7069308e1e1801a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eda6154d16e52c35a10c8d02093e3d4a6204b2985f2aeefcc869a1faefa7605b3847c8ef9d98afd990c11ec969d4be83148bb7be418ac1ad0a2791490f1eaaf4
|
7
|
+
data.tar.gz: dd851cd69e3d919febf1bbadcee2a93ff54cb689aea6015055558b10c03d5702da1fbdf970e91509339142eef254c93c7a8ebe765dc369337d4f42af6935d9ee
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# globby
|
2
2
|
|
3
|
+
[<img src="https://travis-ci.org/jenseng/globby.svg" />](http://travis-ci.org/jenseng/globby)
|
4
|
+
|
3
5
|
globby is a [`.gitignore`](http://www.kernel.org/pub/software/scm/git/docs/gitignore.html)-style
|
4
6
|
file globber for ruby.
|
5
7
|
|
@@ -60,4 +62,4 @@ behaviors are platform independent in globby and can always be used:
|
|
60
62
|
|
61
63
|
## License
|
62
64
|
|
63
|
-
Copyright (c)
|
65
|
+
Copyright (c) 2013-2016 Jon Jensen, released under the MIT license
|
data/lib/globby/glob.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module Globby
|
2
2
|
class Glob
|
3
3
|
def initialize(pattern)
|
4
|
+
pattern = pattern.dup
|
4
5
|
@inverse = pattern.sub!(/\A!/, '')
|
5
6
|
# remove meaningless wildcards
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
pattern.sub!(/\A\/?(\*\*\/)+/, '')
|
8
|
+
pattern.sub!(/(\/\*\*)+\/\*\z/, '/**')
|
9
|
+
@pattern = pattern
|
9
10
|
end
|
10
11
|
|
11
12
|
def match(files)
|
@@ -77,7 +78,7 @@ module Globby
|
|
77
78
|
(part.split(/(#{GLOB_WILDCARD})/) - [""]).inject("") do |result, p|
|
78
79
|
result << case p
|
79
80
|
when '?'; '[^/]'
|
80
|
-
when '*'; '[^/]*'
|
81
|
+
when '*'; '[^/]' + (result.end_with?("/") ? '+' : '*')
|
81
82
|
else Regexp.escape(p)
|
82
83
|
end
|
83
84
|
end
|
data/spec/gitignore_spec.rb
CHANGED
@@ -2,8 +2,6 @@ require 'globby'
|
|
2
2
|
require 'tmpdir'
|
3
3
|
require 'fileutils'
|
4
4
|
|
5
|
-
RSpec.configure { |config| config.mock_framework = :mocha }
|
6
|
-
|
7
5
|
describe Globby do
|
8
6
|
around do |example|
|
9
7
|
gitignore_test { example.run }
|
@@ -12,14 +10,14 @@ describe Globby do
|
|
12
10
|
describe ".select" do
|
13
11
|
it "should match .gitignore perfectly" do
|
14
12
|
rules = prepare_gitignore
|
15
|
-
Globby.select(rules.split(/\n/)).
|
13
|
+
expect(Globby.select(rules.split(/\n/))).to eq(all_files - git_files - untracked)
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
19
17
|
describe ".reject" do
|
20
18
|
it "should match the inverse of .gitignore, plus .git" do
|
21
19
|
rules = prepare_gitignore
|
22
|
-
Globby.reject(rules.split(/\n/)).
|
20
|
+
expect(Globby.reject(rules.split(/\n/))).to eq(git_files + untracked)
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
@@ -49,6 +47,9 @@ describe Globby do
|
|
49
47
|
# except rb files immediately under foobar
|
50
48
|
!foobar/*.rb
|
51
49
|
|
50
|
+
# ooh look **
|
51
|
+
/a/**/*.yuss
|
52
|
+
|
52
53
|
# this will match foo/bar but not bar
|
53
54
|
bar/
|
54
55
|
|
@@ -57,6 +58,10 @@ describe Globby do
|
|
57
58
|
|
58
59
|
# this will match baz/ and foobar/baz/
|
59
60
|
baz
|
61
|
+
|
62
|
+
# check reinclusion
|
63
|
+
/spec/*
|
64
|
+
!/spec/noignore
|
60
65
|
IGNORE
|
61
66
|
File.open('.gitignore', 'w'){ |f| f.write ignore }
|
62
67
|
ignore
|
@@ -77,6 +82,10 @@ describe Globby do
|
|
77
82
|
foobar/baz.txt
|
78
83
|
foobar/baz.rb
|
79
84
|
foobar/baz/lol.wut
|
85
|
+
a/a.yuss
|
86
|
+
a/a/a/a/a.yuss
|
87
|
+
spec/nope
|
88
|
+
spec/noignore
|
80
89
|
FILES
|
81
90
|
files.each do |file|
|
82
91
|
FileUtils.mkdir_p File.dirname(file)
|
@@ -85,7 +94,7 @@ describe Globby do
|
|
85
94
|
end
|
86
95
|
|
87
96
|
def untracked
|
88
|
-
`git status -uall`.gsub(
|
97
|
+
`git status -uall --porcelain`.gsub(/^\?\? /m, '').split(/\n/)
|
89
98
|
end
|
90
99
|
|
91
100
|
def git_files
|
@@ -97,4 +106,4 @@ describe Globby do
|
|
97
106
|
Dir.glob('**/*', File::FNM_DOTMATCH).
|
98
107
|
select{ |f| File.symlink?(f) || File.file?(f) }.sort
|
99
108
|
end
|
100
|
-
end
|
109
|
+
end
|
data/spec/globby_spec.rb
CHANGED
@@ -1,84 +1,82 @@
|
|
1
1
|
require 'globby'
|
2
2
|
|
3
|
-
RSpec.configure { |config| config.mock_framework = :mocha }
|
4
|
-
|
5
3
|
describe Globby do
|
6
4
|
it "should support chaining" do
|
7
5
|
files = files(%w{foo/bar.rb foo/baz.rb foo/c/bar.html foo/c/c/bar.rb})
|
8
|
-
Globby.select(%w{*rb}, files).
|
9
|
-
|
10
|
-
|
6
|
+
expect(Globby.select(%w{*rb}, files).
|
7
|
+
reject(%w{baz*}).
|
8
|
+
select(%w{c})).to eq %w{foo/c/c/bar.rb}
|
11
9
|
end
|
12
10
|
|
13
11
|
describe ".select" do
|
14
12
|
context "a blank line" do
|
15
13
|
it "should return nothing" do
|
16
14
|
files = files("foo")
|
17
|
-
Globby.select([""], files).
|
15
|
+
expect(Globby.select([""], files)).to eq []
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
19
|
context "a comment" do
|
22
20
|
it "should return nothing" do
|
23
21
|
files = files("foo")
|
24
|
-
Globby.select(["#"], files).
|
22
|
+
expect(Globby.select(["#"], files)).to eq []
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
26
|
context "a pattern ending in a slash" do
|
29
27
|
it "should return a matching directory's contents" do
|
30
28
|
files = files(%w{foo/bar/baz foo/bar/baz2})
|
31
|
-
Globby.select(%w{bar/}, files).
|
29
|
+
expect(Globby.select(%w{bar/}, files)).to eq %w{foo/bar/baz foo/bar/baz2}
|
32
30
|
end
|
33
31
|
|
34
32
|
it "should ignore symlinks and regular files" do
|
35
33
|
files = files(%w{foo/bar bar/baz})
|
36
|
-
Globby.select(%w{bar/}, files).
|
34
|
+
expect(Globby.select(%w{bar/}, files)).to eq %w{bar/baz}
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
40
38
|
context "a pattern starting in a slash" do
|
41
39
|
it "should return only root glob matches" do
|
42
40
|
files = files(%w{foo/bar bar/foo})
|
43
|
-
Globby.select(%w{/foo}, files).
|
41
|
+
expect(Globby.select(%w{/foo}, files)).to eq %w{foo/bar}
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
47
45
|
context "a pattern with a *" do
|
48
46
|
it "should return matching files" do
|
49
47
|
files = files(%w{foo/bar foo/baz})
|
50
|
-
Globby.select(%w{*z}, files).
|
48
|
+
expect(Globby.select(%w{*z}, files)).to eq %w{foo/baz}
|
51
49
|
end
|
52
50
|
|
53
51
|
it "should not glob slashes" do
|
54
52
|
files = files(%w{foo/bar foo/baz})
|
55
|
-
Globby.select(%w{foo*bar}, files).
|
53
|
+
expect(Globby.select(%w{foo*bar}, files)).to eq []
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
59
57
|
context "a pattern with a ?" do
|
60
58
|
it "should return matching files" do
|
61
59
|
files = files(%w{foo/bar foo/baz})
|
62
|
-
Globby.select(%w{b?z}, files).
|
60
|
+
expect(Globby.select(%w{b?z}, files)).to eq %w{foo/baz}
|
63
61
|
end
|
64
62
|
|
65
63
|
it "should not glob slashes" do
|
66
64
|
files = files(%w{foo/bar foo/baz})
|
67
|
-
Globby.select(%w{foo?bar}, files).
|
65
|
+
expect(Globby.select(%w{foo?bar}, files)).to eq []
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
71
69
|
context "a pattern with a **" do
|
72
70
|
it "should match directories recursively" do
|
73
71
|
files = files(%w{foo/bar foo/baz foo/c/bar foo/c/c/bar})
|
74
|
-
Globby.select(%w{foo/**/bar}, files).
|
72
|
+
expect(Globby.select(%w{foo/**/bar}, files)).to eq %w{foo/bar foo/c/bar foo/c/c/bar}
|
75
73
|
end
|
76
74
|
end
|
77
75
|
|
78
76
|
context "a pattern with bracket expressions" do
|
79
77
|
it "should return matching files" do
|
80
78
|
files = files(%w{boo fob f0o foo/bar poo/baz})
|
81
|
-
Globby.select(%w{[e-g][0-9[:alpha:]][!b]}, files).
|
79
|
+
expect(Globby.select(%w{[e-g][0-9[:alpha:]][!b]}, files)).to eq %w{f0o foo/bar}
|
82
80
|
end
|
83
81
|
end
|
84
82
|
end
|
@@ -92,4 +90,4 @@ describe Globby do
|
|
92
90
|
}.uniq.sort
|
93
91
|
Globby::GlObject.new files, dirs
|
94
92
|
end
|
95
|
-
end
|
93
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: globby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jon Jensen
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-06-15 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: find files using .gitignore-style globs
|
15
14
|
email: jenseng@gmail.com
|
@@ -18,37 +17,36 @@ extensions: []
|
|
18
17
|
extra_rdoc_files: []
|
19
18
|
files:
|
20
19
|
- LICENSE.txt
|
21
|
-
- Rakefile
|
22
20
|
- README.md
|
21
|
+
- Rakefile
|
22
|
+
- lib/globby.rb
|
23
23
|
- lib/globby/glob.rb
|
24
24
|
- lib/globby/globject.rb
|
25
25
|
- lib/globby/result.rb
|
26
|
-
- lib/globby.rb
|
27
26
|
- spec/gitignore_spec.rb
|
28
27
|
- spec/globby_spec.rb
|
29
28
|
homepage: http://github.com/jenseng/globby
|
30
29
|
licenses: []
|
30
|
+
metadata: {}
|
31
31
|
post_install_message:
|
32
32
|
rdoc_options: []
|
33
33
|
require_paths:
|
34
34
|
- lib
|
35
35
|
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
36
|
requirements:
|
38
|
-
- -
|
37
|
+
- - ">="
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: 1.8.7
|
41
40
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
41
|
requirements:
|
44
|
-
- -
|
42
|
+
- - ">="
|
45
43
|
- !ruby/object:Gem::Version
|
46
44
|
version: 1.3.5
|
47
45
|
requirements: []
|
48
46
|
rubyforge_project:
|
49
|
-
rubygems_version:
|
47
|
+
rubygems_version: 2.2.5
|
50
48
|
signing_key:
|
51
|
-
specification_version:
|
52
|
-
summary: .gitignore-style file globber
|
49
|
+
specification_version: 4
|
50
|
+
summary: ".gitignore-style file globber"
|
53
51
|
test_files: []
|
54
52
|
has_rdoc:
|