dir_glob_ignore 0.1.1 → 0.2.2

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: 59f6e0762503ccdb5cb8d469b478d1c3b90bb649
4
- data.tar.gz: 8858c71953e0bd37cf8cf6df55c458a3041d07cc
3
+ metadata.gz: 838a9f500e255b82b53cca8d8786611597295240
4
+ data.tar.gz: faafb565245cbf90825c35e50f8a61892440d90c
5
5
  SHA512:
6
- metadata.gz: 780257e567922428c89887c77f614a4cd0bbb4db1afc1fa84abc42f4faf1fb3e6846d99558686835b254ae7773899ecf983de4d285bddc15f0de6558b1e5644c
7
- data.tar.gz: b7110afe8f51c0a841c1ac548d853c48a515c71293327dd3279d75fa7bb9026a72661a5b1349cadf336ca31f1310cd92626bc9d1d6ad3ea72a164a7ec2a5b3ae
6
+ metadata.gz: df38cbaba3a85a3163573bb4c021c60c6944ac7021b424ac7ca6b4ce21d5bc4a8cd8dd9d38db1ef53702216528ffca89629ef9584bd6c08385266ef0cd21f1e1
7
+ data.tar.gz: c0d9632f42fb4aef93a87f762a5a6503daa45cf9cfb036cb31876c45d0b740effdcdb152f4c9e6509ce8e522c0c7639eeb02c5a67fef02c0a830cca7dcc7e1ee
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # DirGlobIgnore
2
2
 
3
- Enable file globbing with a-la-git ignore files management.
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 `glob_with_ignore_file`
24
- which allows to specify _a-la-git_ ignore files
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 (except you can't specify
42
- "_positive_" exceptions with "!").
42
+ The format is really simple, inspired by `.gitignore` file format:
43
43
 
44
- You can specify comment lines with "#". Blank lines are ignored.
44
+ * You can specify comment lines with "#".
45
+ * Blank lines are ignored.
46
+ * Patterns are actually any `Dir::glob` valid pattern
45
47
 
46
- Patterns are actually any `Dir::glob` valid pattern
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
 
@@ -1,7 +1,4 @@
1
1
  require 'dir_glob_ignore/version'
2
- require 'dir_glob_ignore/ignore_file_list'
2
+ require 'dir_glob_ignore/ignore_file_lists'
3
3
  require 'dir_glob_ignore/dir_patch'
4
4
 
5
- module DirGlobIgnore
6
- # Your code goes here...
7
- end
@@ -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::IgnoreFileList.new base_dir
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.ignore_list.include? File.expand_path(file)
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 IgnoreFileList
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] = load_ignore_file 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
- build_ignore_list
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 build_ignore_list
35
- ignore_list = []
36
- cache.each do |dir, patterns|
37
- patterns.each do |pattern|
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)
@@ -1,3 +1,3 @@
1
1
  module DirGlobIgnore
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
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.1.1
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-29 00:00:00.000000000 Z
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/ignore_file_list.rb
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: