trick_bag 0.65.1 → 0.66.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: 19559dbd27a0d1a9b604eea19d6a0b18174fdf8b
4
- data.tar.gz: 75d5d546726b5fdbec43dec86e31d566fb08de13
3
+ metadata.gz: 1d232e6acd5101ddede4f818540a495f8cb9a454
4
+ data.tar.gz: b8b773b9d5b40ec1e7e8fe2d61888d59d9a35be0
5
5
  SHA512:
6
- metadata.gz: 42afa58dbeafba8498181647aedc4c7ef9b3ea08dedef5603ba5b9f2e5e2a791c0fa4c878237b2017e2a169a08bafb71066f6b7d376522029a76ba1b39682690
7
- data.tar.gz: 15b6948e4aeadb0f9f948d6a9242f87a60dac0b94ed95aa910dcabf36660ba909c8d47760cb3ac47d6a8b97884b3f6ba78ed069239020620fa31b76297a465ed
6
+ metadata.gz: d90de4a2b882180737bc7ac377b75521e173b1796be0c1204a37a617c3221dfd3140fd391e3da8e9de2c19dff4c16c2b9b05011dc06fabd76a9324cf924aba75
7
+ data.tar.gz: e9d782a5aebcd295387481e6551600747f36539b3ae20a31f4f6db69ec659efd04ac2ee35f3643781ddffa45fcbcbbbad49adbf32a0c1efaaa9d3fa252b29f8f
data/RELEASE_NOTES.md CHANGED
@@ -1,8 +1,24 @@
1
+ ## v0.66.0
2
+
3
+ * Add TrickBag::Io::Gitignore.list_ignored_files.
4
+
5
+
6
+
7
+ ## v0.65.1
8
+
9
+ * Fix bug in TrickBag::Validations when raise_on_missing_keys was passed an array.
10
+
11
+
12
+ ## v0.65.0
13
+ * Add ability to pass values through print() to TextModeStatusUpdater's text generator. Version 0.65.0.
14
+
15
+
1
16
  ## v0.64.5
2
17
 
3
18
  * Modified .travis.yml. as per suggestion on web to fix bundler problem:
4
19
  NoMethodError: undefined method `spec' for nil:NilClass
5
20
 
21
+
6
22
  ## v0.64.4
7
23
 
8
24
  * Fix net-ssh version error on Ruby versions < 2. v0.64.2 did not work.
@@ -22,7 +22,7 @@ class FileLineReader
22
22
 
23
23
  attr_reader :filespec, :start_and_max
24
24
 
25
- # @param filespec - the file from which to read domain names; blank/empty lines and lines
25
+ # @param filespec - the file from which to read lines; blank/empty lines and lines
26
26
  # with the first nonblank character == '#' will be ignored.
27
27
  # @param start_pos - the record number, zero offset, at which to begin each() processing
28
28
  # @param max_count - the maximum number of records to be served by each()
@@ -0,0 +1,41 @@
1
+ module TrickBag
2
+ module Io
3
+
4
+ # This module implements in Ruby the behavior of git's handling of the .gitignore file.
5
+ # It assumes that the current working directory is the directory of the .gitignore file.
6
+
7
+ module Gitignore
8
+
9
+ module_function
10
+
11
+ # Lists files that exist that would be ignored by git based on the .gitignore file
12
+ # You may provide an Enumerable with the values that would normally be in the .gitignore file.
13
+ def list_ignored_files(ignore_spec = File.readlines('.gitignore'))
14
+ ignore_list = ignore_spec.each_with_object([]) do |exclude_mask, ignore_list|
15
+ exclude_mask << '**/*' if exclude_mask[-1] == '/'
16
+ exclude_files = Dir.glob(exclude_mask, File::FNM_DOTMATCH)
17
+ ignore_list.concat(exclude_files)
18
+ end
19
+
20
+ ignore_list.sort!
21
+ ignore_list.uniq!
22
+ ignore_list.delete('.')
23
+ ignore_list.delete('..')
24
+ ignore_list.reject! { |filespec| File.directory?(filespec) }
25
+ ignore_list
26
+ end
27
+
28
+
29
+ # Lists files that exist that would *NOT* be ignored by git based on the .gitignore file
30
+ # You may provide an Enumerable with the values that would normally be in the .gitignore file.
31
+ def list_included_files(ignore_spec = File.readlines('.gitignore'))
32
+ all_files = Dir.glob('**/*', File::FNM_DOTMATCH).reject do |filespec|
33
+ File.directory?(filespec)
34
+ end
35
+ all_files - list_ignored_files(ignore_spec)
36
+ end
37
+ end
38
+
39
+ end
40
+ end
41
+
@@ -1,3 +1,5 @@
1
+ require 'tempfile'
2
+
1
3
  module TrickBag
2
4
  module Io
3
5
  module TempFiles
@@ -1,3 +1,3 @@
1
1
  module TrickBag
2
- VERSION = '0.65.1'
3
- end
2
+ VERSION = '0.66.0'
3
+ end
@@ -0,0 +1,138 @@
1
+ require 'set'
2
+ require 'tmpdir'
3
+
4
+ require_relative '../../spec_helper'
5
+ require_relative '../../../lib/trick_bag/io/gitignore'
6
+
7
+ GI=TrickBag::Io::Gitignore
8
+
9
+ describe TrickBag::Io::Gitignore do
10
+ shared_examples_for 'testing a pair' do |ignore_spec, expected_result, filename|
11
+ let(:ignored_files) { GI.list_ignored_files }
12
+ let(:in_ignore_list) { ignored_files.include?(filename) }
13
+ let(:error_message) do
14
+ "filename: '#{filename}', ignore_spec: #{ignore_spec}, expected result: #{expected_result}, got: #{in_ignore_list}, ignored files: #{ignored_files}"
15
+ end
16
+
17
+ around do |example|
18
+ Dir.mktmpdir do |tmpdir|
19
+ Dir.chdir(tmpdir) do
20
+ File.write('.gitignore', ignore_spec.join("\n"))
21
+ Dir.mkdir('a_dir') # for some but not all tests
22
+ Dir.mkdir('.hidden_dir') # for some but not all tests
23
+ FileUtils.touch(filename) # for some but not all tests
24
+ example.run
25
+ end
26
+ end
27
+ end
28
+
29
+ it { expect(in_ignore_list).to eq(expected_result), error_message }
30
+ end
31
+
32
+ context 'handling a nonhidden file in the root directory', :aggregate_failures do
33
+ test_inputs = [
34
+ [[], false],
35
+ [['target'], true],
36
+ [['**/*arge*'], true],
37
+ [['*'], true],
38
+ [['*arge*'], true],
39
+ ]
40
+
41
+ test_inputs.each do |(ignore_spec, expected_result)|
42
+ context do # without a context block the way that rspec expands the examples causes the parameters to overwrite each other
43
+ include_examples 'testing a pair', ignore_spec, expected_result, 'target'
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'handling a hidden file in the root directory', :aggregate_failures do
49
+ test_inputs = [
50
+ [[], false],
51
+ [['.target'], true],
52
+ [['**/*arge*'], true],
53
+ [['**/.targe*'], true],
54
+ [['*'], true],
55
+ [['*arge*'], true],
56
+ ]
57
+
58
+ test_inputs.each do |(ignore_spec, expected_result)|
59
+ context do # without a context block the way that rspec expands the examples causes the parameters to overwrite each other
60
+ include_examples 'testing a pair', ignore_spec, expected_result, '.target'
61
+ end
62
+ end
63
+ end
64
+
65
+ context 'handling hidden files in subdirectories of hidden directories', :aggregate_failures do
66
+ test_inputs = [
67
+ [[], false],
68
+ [['.hidden_dir'], false],
69
+ [['.hidden_dir/'], true],
70
+ [['hidden_dir/'], false],
71
+ [['.hidden_dir/.*'], true],
72
+ [['.hidden_dir/.hidden_file'], true],
73
+ ]
74
+
75
+ test_inputs.each do |(ignore_spec, expected_result)|
76
+ context do # without a context block the way that rspec expands the examples causes the parameters to overwrite each other
77
+ include_examples 'testing a pair', ignore_spec, expected_result, '.hidden_dir/.hidden_file'
78
+ end
79
+ end
80
+ end
81
+
82
+ it 'should take an Enumerable that is not an Array' do
83
+ GI.list_ignored_files(Set.new(['target']))
84
+ end
85
+
86
+ context 'directories should not be included', :aggregate_failures do
87
+ context { include_examples 'testing a pair', ['*'], false, 'a_dir' }
88
+ context { include_examples 'testing a pair', ['*'], false, '.hidden_dir' }
89
+ end
90
+
91
+ context 'includes should be all files not in ignore list', :aggregate_failures do
92
+ test_inputs = [
93
+ [],
94
+ ['*'],
95
+ ['**/*'],
96
+ ['x/y/z'],
97
+ ['x/y/z/*'],
98
+ ['x/y/z/**/*'],
99
+ ['x/y/z/**/deep'],
100
+ ['.hidden_dir'],
101
+ ['.hidden_dir/'],
102
+ ['hidden_dir/'],
103
+ ['.hidden_dir/.*'],
104
+ ['.hidden_dir/.hidden_file'],
105
+ ]
106
+
107
+ around do |example|
108
+ Dir.mktmpdir do |tmpdir|
109
+ Dir.chdir(tmpdir) do
110
+ %w(a_dir .hidden_dir x/y/z).each { |dirspec| FileUtils.mkdir_p(dirspec) }
111
+ %w(root a_dir/sub .hidden_dir/.hidden_file x/y/z/deep).each { |f| FileUtils.touch(f) }
112
+ File.write('.gitignore', ignore_spec.join("\n"))
113
+ example.run
114
+ end
115
+ end
116
+ end
117
+
118
+ test_inputs.each do |ignore_spec|
119
+ context do
120
+ let(:ignore_spec) { ignore_spec }
121
+ let(:ignored_files) { GI.list_ignored_files(ignore_spec).sort }
122
+ let(:included_files) { GI.list_included_files(ignore_spec).sort }
123
+ let(:intersection) { included_files & ignored_files }
124
+ let(:union) { (included_files | ignored_files).sort }
125
+ let(:all_files) do
126
+ Dir.glob('**/*', File::FNM_DOTMATCH).reject do |filespec|
127
+ File.directory?(filespec)
128
+ end.sort
129
+ end
130
+
131
+ it { expect(intersection).to eq([]),
132
+ "expected no overlap between ignored and included for #{ignore_spec}, got #{intersection}" }
133
+ it { expect(union).to eq(all_files),
134
+ "expected ignored and included to contain all files for #{ignore_spec}, but neither contained: #{all_files - union}" }
135
+ end
136
+ end
137
+ end
138
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trick_bag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.65.1
4
+ version: 0.66.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Bennett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-09 00:00:00.000000000 Z
11
+ date: 2017-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: os
@@ -150,6 +150,7 @@ files:
150
150
  - lib/trick_bag/formatters/erb_renderer.rb
151
151
  - lib/trick_bag/formatters/formatters.rb
152
152
  - lib/trick_bag/functional/functional.rb
153
+ - lib/trick_bag/io/gitignore.rb
153
154
  - lib/trick_bag/io/temp_files.rb
154
155
  - lib/trick_bag/io/text_mode_status_updater.rb
155
156
  - lib/trick_bag/meta/classes.rb
@@ -183,6 +184,7 @@ files:
183
184
  - spec/trick_bag/formatters/erb_renderer_spec.rb
184
185
  - spec/trick_bag/formatters/formatters_spec.rb
185
186
  - spec/trick_bag/functional/functional_spec.rb
187
+ - spec/trick_bag/io/gitignore_spec.rb
186
188
  - spec/trick_bag/io/temp_files_spec.rb
187
189
  - spec/trick_bag/io/text_mode_status_updater_spec.rb
188
190
  - spec/trick_bag/meta/classes_spec.rb
@@ -221,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
223
  version: '0'
222
224
  requirements: []
223
225
  rubyforge_project:
224
- rubygems_version: 2.6.10
226
+ rubygems_version: 2.6.13
225
227
  signing_key:
226
228
  specification_version: 4
227
229
  summary: Miscellaneous general useful tools.
@@ -239,6 +241,7 @@ test_files:
239
241
  - spec/trick_bag/formatters/erb_renderer_spec.rb
240
242
  - spec/trick_bag/formatters/formatters_spec.rb
241
243
  - spec/trick_bag/functional/functional_spec.rb
244
+ - spec/trick_bag/io/gitignore_spec.rb
242
245
  - spec/trick_bag/io/temp_files_spec.rb
243
246
  - spec/trick_bag/io/text_mode_status_updater_spec.rb
244
247
  - spec/trick_bag/meta/classes_spec.rb