dir_glob_ignore 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -9
- data/lib/dir_glob_ignore.rb +1 -4
- data/lib/dir_glob_ignore/dir_patch.rb +3 -3
- data/lib/dir_glob_ignore/{ignore_file_list.rb → ignore_file_lists.rb} +18 -10
- data/lib/dir_glob_ignore/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 838a9f500e255b82b53cca8d8786611597295240
|
4
|
+
data.tar.gz: faafb565245cbf90825c35e50f8a61892440d90c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df38cbaba3a85a3163573bb4c021c60c6944ac7021b424ac7ca6b4ce21d5bc4a8cd8dd9d38db1ef53702216528ffca89629ef9584bd6c08385266ef0cd21f1e1
|
7
|
+
data.tar.gz: c0d9632f42fb4aef93a87f762a5a6503daa45cf9cfb036cb31876c45d0b740effdcdb152f4c9e6509ce8e522c0c7639eeb02c5a67fef02c0a830cca7dcc7e1ee
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# DirGlobIgnore
|
2
2
|
|
3
|
-
|
3
|
+
Adds _a-la-git_ features to `Dir::glob`, so that file selection will
|
4
|
+
take in account custom _ignore_ files.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -20,10 +21,10 @@ Or install it yourself as:
|
|
20
21
|
|
21
22
|
## Usage
|
22
23
|
|
23
|
-
Once required this gem patches the `Dir` Ruby core class by adding a new method
|
24
|
-
which allows to specify
|
24
|
+
Once required this gem patches the `Dir` Ruby core class by adding a new method `::glob_with_ignore_file`
|
25
|
+
which allows to specify _a-la-git_ ignore files.
|
25
26
|
|
26
|
-
Like with Git, there can be multiple ignore files in sub-directories
|
27
|
+
Like with Git, there can be multiple ignore files in sub-directories...
|
27
28
|
|
28
29
|
```ruby
|
29
30
|
require 'dir_glob_ignore'
|
@@ -31,19 +32,26 @@ require 'dir_glob_ignore'
|
|
31
32
|
Dir.glob_with_ignore_file '.my_ignore_file', '/a/root/directory', *standard_glob_options
|
32
33
|
```
|
33
34
|
|
34
|
-
* The first parameter specifies the name of the ignore files to look for.
|
35
|
+
* The first parameter specifies the name (without path) of the ignore files to look for.
|
35
36
|
* The second parameter specifies a root directory for ignore files. This is not a root directory
|
36
37
|
for the glob function but actually defines where to search ignore files.
|
37
38
|
* Then the remaining parameters are identical to the ones you could pass to `Dir::glob`
|
38
39
|
|
39
40
|
## Ignore files format
|
40
41
|
|
41
|
-
The format is really simple, inspired by `.gitignore` file format
|
42
|
-
"_positive_" exceptions with "!").
|
42
|
+
The format is really simple, inspired by `.gitignore` file format:
|
43
43
|
|
44
|
-
You can specify comment lines with "#".
|
44
|
+
* You can specify comment lines with "#".
|
45
|
+
* Blank lines are ignored.
|
46
|
+
* Patterns are actually any `Dir::glob` valid pattern
|
45
47
|
|
46
|
-
|
48
|
+
## Current limitations and TODOs
|
49
|
+
|
50
|
+
### Positive patterns
|
51
|
+
|
52
|
+
Currently you can't specify a "_positive_" pattern like in `.gitignore` files (using "!").
|
53
|
+
|
54
|
+
PR welcome...
|
47
55
|
|
48
56
|
## Contributing
|
49
57
|
|
data/lib/dir_glob_ignore.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
class Dir
|
2
2
|
|
3
3
|
def self.glob_with_ignore_file(ignore_file, base_dir, *glob_args, &block)
|
4
|
-
filter = DirGlobIgnore::
|
5
|
-
filter.ignore_file_name =ignore_file
|
4
|
+
filter = DirGlobIgnore::IgnoreFileLists.new base_dir
|
5
|
+
filter.ignore_file_name = ignore_file
|
6
6
|
filter.load_ignore_files
|
7
7
|
Dir.glob(*glob_args).reject do |file|
|
8
|
-
if filter.
|
8
|
+
if filter.ignore_file? file
|
9
9
|
true
|
10
10
|
else
|
11
11
|
yield file if block_given?
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module DirGlobIgnore
|
2
2
|
|
3
|
-
class
|
3
|
+
class IgnoreFileLists
|
4
4
|
|
5
5
|
DEFAULT_FILE_NAME = '.ignore'.freeze
|
6
6
|
|
7
7
|
attr_writer :ignore_file_name, :base_dir
|
8
|
-
attr_reader :ignore_list
|
9
8
|
|
10
9
|
def initialize(base_dir = nil)
|
11
10
|
self.base_dir = base_dir
|
@@ -22,23 +21,32 @@ module DirGlobIgnore
|
|
22
21
|
def load_ignore_files
|
23
22
|
@cache = {}
|
24
23
|
ignore_files.each do |ignore_file|
|
25
|
-
cache[File.expand_path File.dirname ignore_file] =
|
24
|
+
cache[File.expand_path File.dirname ignore_file] = {
|
25
|
+
ignore_file: ignore_file,
|
26
|
+
patterns: load_ignore_file(ignore_file),
|
27
|
+
ignored_files: []
|
28
|
+
}
|
26
29
|
end
|
27
|
-
|
30
|
+
build_cached_ignore_lists
|
31
|
+
end
|
32
|
+
|
33
|
+
def ignore_file?(file)
|
34
|
+
cache.values.each do |info|
|
35
|
+
return true if info[:ignored_files].include? File.expand_path(file)
|
36
|
+
end
|
37
|
+
false
|
28
38
|
end
|
29
39
|
|
30
40
|
private
|
31
41
|
|
32
42
|
attr_reader :cache
|
33
43
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
ignore_list.concat Dir.glob(File.join(dir, pattern), File::FNM_DOTMATCH)
|
44
|
+
def build_cached_ignore_lists
|
45
|
+
cache.each do |dir, info|
|
46
|
+
info[:patterns].each do |pattern|
|
47
|
+
info[:ignored_files].concat Dir.glob(File.join(dir, pattern), File::FNM_DOTMATCH)
|
39
48
|
end
|
40
49
|
end
|
41
|
-
@ignore_list = ignore_list.sort.uniq
|
42
50
|
end
|
43
51
|
|
44
52
|
def load_ignore_file(ignore_file)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dir_glob_ignore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurent B.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,7 +72,7 @@ files:
|
|
72
72
|
- dir_glob_ignore.gemspec
|
73
73
|
- lib/dir_glob_ignore.rb
|
74
74
|
- lib/dir_glob_ignore/dir_patch.rb
|
75
|
-
- lib/dir_glob_ignore/
|
75
|
+
- lib/dir_glob_ignore/ignore_file_lists.rb
|
76
76
|
- lib/dir_glob_ignore/version.rb
|
77
77
|
homepage: https://github.com/lbriais/dir_glob_ignore.git
|
78
78
|
licenses:
|