path_expander 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bb707e47c24f77a4b4a2d23c8db936f9b6d0b9db
4
- data.tar.gz: f69d58051c1c4a8d38e7c762bf164cc4b2b96055
2
+ SHA256:
3
+ metadata.gz: 95157151cd3523ba3bcd9ca1668dbfa436e87b9dfabb3431ca218ea66571c436
4
+ data.tar.gz: b0714ed15b27ae4b4dc16f1f87ec20dd2732299ffbadff80b9e51ba004855ef6
5
5
  SHA512:
6
- metadata.gz: c91cc5482ca821c474986e05cfc0d1b337f1cd9c2632fd323578e9f0a5e8789825204c9ebd748d26ca7b97bb184225555c96459724cfd1b6f88dbb43b3f1661f
7
- data.tar.gz: 0b50d8770583b077005a75039a972ca2b7f1e1b4f766c8d0772f891b2a43972bc5157433a1ae51a1511de430d6538dfbe7a28197cb043b2e9bb7f67023e167cb
6
+ metadata.gz: c53f545816dc9c6341c1bddfede9b4ef137e64100dd4883df1ee7bf81d4df2adf91f78fabfa2ce431d1f85c03d65941dadd6e1e8b50de6f27ab9a63724da1398
7
+ data.tar.gz: 017eb994f9a635e8b780d326a364cae4fc82fd3852cd792c8819ccb9550539b14f49fc01a68b076a7fb367a7e6020099b7dfb9d6f5134cc33cb464ea13fabf9d
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,6 +1,47 @@
1
+ === 1.1.1 / 2022-07-03
2
+
3
+ * 1 bug fix:
4
+
5
+ * Process plain '-' as a file, not an option.
6
+
7
+ === 1.1.0 / 2019-09-22
8
+
9
+ * 1 minor enhancement:
10
+
11
+ * Added a default path (default: ".") to scan if no files are initially found.
12
+
13
+ === 1.0.5 / 2019-09-14
14
+
15
+ * 1 bug fix:
16
+
17
+ * Fixed a deprecation warning from File.exists?
18
+
19
+ === 1.0.4 / 2019-05-26
20
+
21
+ * 1 bug fix:
22
+
23
+ * Sorted the output from expand_dirs_to_files. (deivid-rodriguez)
24
+
25
+ === 1.0.3 / 2018-03-16
26
+
27
+ * 1 bug fix:
28
+
29
+ * Don't process files if path expands to root directory. Prevents -n /./ from hanging.
30
+
31
+ === 1.0.2 / 2017-05-09
32
+
33
+ * 1 bug fix:
34
+
35
+ * Fixed expand_dirs_to_files returning non-files on glob expansion.
36
+
37
+ === 1.0.1 / 2016-11-30
38
+
39
+ * 1 bug fix:
40
+
41
+ * Expanded paths in filter_files to fix globs w/ absolute paths. (mknapik)
42
+
1
43
  === 1.0.0 / 2016-05-11
2
44
 
3
45
  * 1 major enhancement
4
46
 
5
47
  * Birthday!
6
-
data/Manifest.txt CHANGED
@@ -4,5 +4,6 @@ Manifest.txt
4
4
  README.rdoc
5
5
  Rakefile
6
6
  lib/path_expander.rb
7
+ test/bad_named_dir.rb/.ignore
7
8
  test/test_bad.rb
8
9
  test/test_path_expander.rb
data/README.rdoc CHANGED
@@ -32,7 +32,7 @@ PathExpander.
32
32
  MY_GLOB = "**/*.rb"
33
33
 
34
34
  def initialize args = ARGV
35
- super args, TEST_GLOB
35
+ super args, MY_GLOB
36
36
  end
37
37
  end
38
38
 
data/lib/path_expander.rb CHANGED
@@ -13,7 +13,7 @@
13
13
  # PathExpander.
14
14
 
15
15
  class PathExpander
16
- VERSION = "1.0.0" # :nodoc:
16
+ VERSION = "1.1.1" # :nodoc:
17
17
 
18
18
  ##
19
19
  # The args array to process.
@@ -25,13 +25,20 @@ class PathExpander
25
25
 
26
26
  attr_accessor :glob
27
27
 
28
+ ##
29
+ # The path to scan if no paths are found in the initial scan.
30
+
31
+ attr_accessor :path
32
+
28
33
  ##
29
34
  # Create a new path expander that operates on args and expands via
30
- # glob as necessary.
35
+ # glob as necessary. Takes an optional +path+ arg to fall back on if
36
+ # no paths are found on the initial scan (see #process_args).
31
37
 
32
- def initialize args, glob
38
+ def initialize args, glob, path = "."
33
39
  self.args = args
34
40
  self.glob = glob
41
+ self.path = path
35
42
  end
36
43
 
37
44
  ##
@@ -42,11 +49,11 @@ class PathExpander
42
49
  def expand_dirs_to_files *dirs
43
50
  dirs.flatten.map { |p|
44
51
  if File.directory? p then
45
- Dir[File.join(p, glob)]
52
+ Dir[File.join(p, glob)].find_all { |f| File.file? f }
46
53
  else
47
54
  p
48
55
  end
49
- }.flatten
56
+ }.flatten.sort
50
57
  end
51
58
 
52
59
  ##
@@ -67,28 +74,40 @@ class PathExpander
67
74
  # -not_a_path :: Add to flags to be processed.
68
75
  # dir_path :: Expand and add to files to be processed.
69
76
  # file_path :: Add to files to be processed.
77
+ # - :: Add "-" (stdin) to files to be processed.
70
78
  #
71
79
  # See expand_dirs_to_files for details on how expansion occurs.
72
80
  #
73
81
  # Subtraction happens last, regardless of argument ordering.
82
+ #
83
+ # If no files are found (which is not the same as having an empty
84
+ # file list after subtraction), then fall back to expanding on the
85
+ # default #path given to initialize.
74
86
 
75
87
  def process_args
76
88
  pos_files = []
77
89
  neg_files = []
78
90
  flags = []
91
+ clean = true
79
92
 
80
93
  args.each do |arg|
81
94
  case arg
82
95
  when /^@(.*)/ then # push back on, so they can have dirs/-/@ as well
96
+ clean = false
83
97
  args.concat process_file $1
98
+ when "-" then
99
+ pos_files << arg
84
100
  when /^-(.*)/ then
85
101
  if File.exist? $1 then
102
+ clean = false
86
103
  neg_files += expand_dirs_to_files($1)
87
104
  else
88
105
  flags << arg
89
106
  end
90
107
  else
91
- if File.exist? arg then
108
+ root_path = File.expand_path(arg) == "/" # eg: -n /./
109
+ if File.exist? arg and not root_path then
110
+ clean = false
92
111
  pos_files += expand_dirs_to_files(arg)
93
112
  else
94
113
  flags << arg
@@ -96,7 +115,10 @@ class PathExpander
96
115
  end
97
116
  end
98
117
 
99
- [pos_files - neg_files, flags]
118
+ files = pos_files - neg_files
119
+ files += expand_dirs_to_files(self.path) if files.empty? && clean
120
+
121
+ [files, flags]
100
122
  end
101
123
 
102
124
  ##
@@ -143,7 +165,7 @@ class PathExpander
143
165
  def filter_files files, ignore
144
166
  ignore_paths = if ignore.respond_to? :read then
145
167
  ignore.read
146
- elsif File.exists? ignore then
168
+ elsif File.exist? ignore then
147
169
  File.read ignore
148
170
  end
149
171
 
@@ -152,8 +174,13 @@ class PathExpander
152
174
  dirs, ifiles = nonglobs.partition { |p| p.end_with? "/" }
153
175
  dirs = dirs.map { |s| s.chomp "/" }
154
176
 
177
+ dirs.map! { |i| File.expand_path i }
178
+ globs.map! { |i| File.expand_path i }
179
+ ifiles.map! { |i| File.expand_path i }
180
+
155
181
  only_paths = File::FNM_PATHNAME
156
182
  files = files.reject { |f|
183
+ f = File.expand_path(f)
157
184
  dirs.any? { |i| File.fnmatch?(i, File.dirname(f), only_paths) } ||
158
185
  globs.any? { |i| File.fnmatch?(i, f) } ||
159
186
  ifiles.any? { |i| File.fnmatch?(i, f, only_paths) }
File without changes
@@ -17,10 +17,14 @@ class TestPathExpander < Minitest::Test
17
17
  assert_equal exp, act
18
18
  end
19
19
 
20
+ def assert_filter_files_absolute_paths exp, filter, files = [File.join(Dir.pwd, 'test/dog_and_cat.rb')]
21
+ assert_filter_files exp, filter, files
22
+ end
23
+
20
24
  def assert_process_args exp_files, exp_args, *args
21
25
  expander.args.concat args
22
26
 
23
- assert_equal [exp_files, exp_args], expander.process_args
27
+ assert_equal [exp_files.sort, exp_args], expander.process_args
24
28
  end
25
29
 
26
30
  def test_expand_dirs_to_files
@@ -30,16 +34,30 @@ class TestPathExpander < Minitest::Test
30
34
  assert_equal %w[Rakefile], expander.expand_dirs_to_files("Rakefile")
31
35
  end
32
36
 
37
+ def test_expand_dirs_to_files_sorting
38
+ exp = %w[test/test_bad.rb test/test_path_expander.rb]
39
+ input = %w[test/test_path_expander.rb test/test_bad.rb]
40
+
41
+ assert_equal exp, expander.expand_dirs_to_files(*input)
42
+ assert_equal %w[Rakefile], expander.expand_dirs_to_files("Rakefile")
43
+ end
44
+
33
45
  def test_filter_files_dir
34
46
  assert_filter_files [], "test/"
47
+ assert_filter_files_absolute_paths [], "test/"
35
48
  end
36
49
 
37
50
  def test_filter_files_files
38
- assert_filter_files [], "test/*.rb"
39
-
40
51
  example = %w[test/file.rb test/sub/file.rb top/test/perf.rb]
52
+ example_absolute_paths = example.map { |e| File.join(Dir.pwd, e) }
53
+
54
+ assert_filter_files [], "test/*.rb"
41
55
 
42
56
  assert_filter_files example[1..-1], "test/*.rb", example
57
+
58
+ assert_filter_files_absolute_paths [], "test/*.rb"
59
+
60
+ assert_filter_files_absolute_paths example_absolute_paths[1..-1], "test/*.rb", example_absolute_paths
43
61
  end
44
62
 
45
63
  def test_filter_files_glob
@@ -47,12 +65,22 @@ class TestPathExpander < Minitest::Test
47
65
  assert_filter_files [], "test*", ["test/lib/woot.rb"]
48
66
  assert_filter_files [], "*.rb"
49
67
  assert_filter_files [], "*dog*.rb"
68
+
69
+ assert_filter_files_absolute_paths [], "test*"
70
+ assert_filter_files_absolute_paths [], "test*", [File.join(Dir.pwd, "test/lib/woot.rb")]
71
+ assert_filter_files_absolute_paths [], "*.rb"
72
+ assert_filter_files_absolute_paths [], "*dog*.rb"
50
73
  end
51
74
 
52
75
  def test_filter_files_glob_miss
53
76
  miss = %w[test/dog_and_cat.rb]
77
+ miss_absolute = [File.join(Dir.pwd, 'test/dog_and_cat.rb')]
78
+
54
79
  assert_filter_files miss, "test"
55
80
  assert_filter_files miss, "nope"
81
+
82
+ assert_filter_files_absolute_paths miss_absolute, "test"
83
+ assert_filter_files_absolute_paths miss_absolute, "nope"
56
84
  end
57
85
 
58
86
  def test_process
@@ -122,6 +150,27 @@ class TestPathExpander < Minitest::Test
122
150
  "42")
123
151
  end
124
152
 
153
+ def test_process_args_root
154
+ assert_process_args(%w[],
155
+ %w[-n /./],
156
+ "-n",
157
+ "/./")
158
+ end
159
+
160
+ def test_process_args_no_files
161
+ self.expander = PathExpander.new args, "*.rb", "test" # extra test default
162
+
163
+ assert_process_args(%w[test/test_bad.rb test/test_path_expander.rb],
164
+ %w[-v],
165
+ "-v")
166
+ end
167
+
168
+ def test_process_args_dash
169
+ assert_process_args(%w[-],
170
+ %w[-v],
171
+ "-", "-v")
172
+ end
173
+
125
174
  def test_process_flags
126
175
  exp = %w[a b c]
127
176
  act = expander.process_flags %w[a b c]
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: path_expander
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDPjCCAiagAwIBAgIBAzANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
13
+ MIIDPjCCAiagAwIBAgIBBjANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
14
14
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
15
- GRYDY29tMB4XDTE1MDkxOTIwNTEyMloXDTE2MDkxODIwNTEyMlowRTETMBEGA1UE
15
+ GRYDY29tMB4XDTIxMTIyMzIzMTkwNFoXDTIyMTIyMzIzMTkwNFowRTETMBEGA1UE
16
16
  AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
17
17
  JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
18
18
  b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
@@ -21,44 +21,50 @@ cert_chain:
21
21
  GiadM9GHRaDiaxuX0cIUBj19T01mVE2iymf9I6bEsiayK/n6QujtyCbTWsAS9Rqt
22
22
  qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
23
23
  gBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
24
- HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBBQUAA4IB
25
- AQB+Hx8xUgrpZa4P8H8gR8zme5kISwQrG80MbpqJV6/G3/ZicRFhN5sjwu0uHGue
26
- bd9Cymf6oIRwHVarJux2M32T6bL07Hmi07w2QaPc3MnMKB/D46SRZ2JSSGPFRBTc
27
- SilobMRoGs/7B15uGFUEnNrCB/ltMqhwwSx1r++UQPfeySHEV9uqu03E5Vb7J37O
28
- 2Er6PLXHRiYsIycD1LkMi6YnixdITRHmrqJYE2rsjaIfpIehiusVAPHkNf7qbpHq
29
- qx3h45R1CAsObX0SQDIT+rRbQrtKz1GHIZTOFYvEJjUY1XmRTZupD3CJ8Q7sDqSy
30
- NLq5jm1fq6Y9Uolu3RJbmycf
24
+ HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBCwUAA4IB
25
+ AQCKB5jfsuSnKb+t/Wrh3UpdkmX7TrEsjVmERC0pPqzQ5GQJgmEXDD7oMgaKXaAq
26
+ x2m+KSZDrqk7c8uho5OX6YMqg4KdxehfSLqqTZGoeV78qwf/jpPQZKTf+W9gUSJh
27
+ zsWpo4K50MP+QtdSbKXZwjAafpQ8hK0MnnZ/aeCsW9ov5vdXpYbf3dpg6ADXRGE7
28
+ lQY2y1tJ5/chqu6h7dQmnm2ABUqx9O+JcN9hbCYoA5i/EeubUEtFIh2w3SpO6YfB
29
+ JFmxn4h9YO/pVdB962BdBNNDia0kgIjI3ENnkLq0dKpYU3+F3KhEuTksLO0L6X/V
30
+ YsuyUzsMz6GQA4khyaMgKNSD
31
31
  -----END CERTIFICATE-----
32
- date: 2016-05-13 00:00:00.000000000 Z
32
+ date: 2022-07-04 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rdoc
36
36
  requirement: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4.0'
41
+ - - "<"
42
+ - !ruby/object:Gem::Version
43
+ version: '7'
41
44
  type: :development
42
45
  prerelease: false
43
46
  version_requirements: !ruby/object:Gem::Requirement
44
47
  requirements:
45
- - - ~>
48
+ - - ">="
46
49
  - !ruby/object:Gem::Version
47
50
  version: '4.0'
51
+ - - "<"
52
+ - !ruby/object:Gem::Version
53
+ version: '7'
48
54
  - !ruby/object:Gem::Dependency
49
55
  name: hoe
50
56
  requirement: !ruby/object:Gem::Requirement
51
57
  requirements:
52
- - - ~>
58
+ - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '3.15'
60
+ version: '3.24'
55
61
  type: :development
56
62
  prerelease: false
57
63
  version_requirements: !ruby/object:Gem::Requirement
58
64
  requirements:
59
- - - ~>
65
+ - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '3.15'
67
+ version: '3.24'
62
68
  description: |-
63
69
  PathExpander helps pre-process command-line arguments expanding
64
70
  directories into their constituent files. It further helps by
@@ -81,38 +87,39 @@ extra_rdoc_files:
81
87
  - Manifest.txt
82
88
  - README.rdoc
83
89
  files:
84
- - .autotest
90
+ - ".autotest"
85
91
  - History.rdoc
86
92
  - Manifest.txt
87
93
  - README.rdoc
88
94
  - Rakefile
89
95
  - lib/path_expander.rb
96
+ - test/bad_named_dir.rb/.ignore
90
97
  - test/test_bad.rb
91
98
  - test/test_path_expander.rb
92
99
  homepage: https://github.com/seattlerb/path_expander
93
100
  licenses:
94
101
  - MIT
95
- metadata: {}
96
- post_install_message:
102
+ metadata:
103
+ homepage_uri: https://github.com/seattlerb/path_expander
104
+ post_install_message:
97
105
  rdoc_options:
98
- - --main
106
+ - "--main"
99
107
  - README.rdoc
100
108
  require_paths:
101
109
  - lib
102
110
  required_ruby_version: !ruby/object:Gem::Requirement
103
111
  requirements:
104
- - - '>='
112
+ - - ">="
105
113
  - !ruby/object:Gem::Version
106
114
  version: '0'
107
115
  required_rubygems_version: !ruby/object:Gem::Requirement
108
116
  requirements:
109
- - - '>='
117
+ - - ">="
110
118
  - !ruby/object:Gem::Version
111
119
  version: '0'
112
120
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.4.5
115
- signing_key:
121
+ rubygems_version: 3.3.12
122
+ signing_key:
116
123
  specification_version: 4
117
124
  summary: PathExpander helps pre-process command-line arguments expanding directories
118
125
  into their constituent files
metadata.gz.sig CHANGED
@@ -1,3 +1,2 @@
1
- �V�[�F͜!yľ!l��N�5[�)�%htK4��!�����/�>���{�^P()�4&�
2
- ���X�^�j*���
3
- n�.�^A����?N�;�d����"k��ρ��ʣ�($(�z�@�|���x��c�� �׊$ �6I+y�AR���Zj�; K�y�����؟�vf��.{�T������� �{t92��h̐9S��P�v���#�̸|����Ⳕ��H����/Ч�����@%0%Bv3��^�+��
1
+ ,�n�]EΆ�jS{nh�m�v�)���Ӷ�{�!�$iI�,L�o�'i�Aэԍ\���![g�� 2[݄�AvȽ�s9kn"IQ�`T�QAa�l�%���}e�N,%��轴ʨ�g\��C�#I��dž1�?�H���-X '�\ѻmE�g���#�m�Ţ�.�ח��u�4ڂd8� ׊�j��30@`LP�%9���J��ȚE;�1�&�<8�T�,�
2
+ ��"�����5�jY�?EL���q��@����