path_expander 1.0.5 → 1.1.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +6 -0
- data/lib/path_expander.rb +22 -4
- data/test/test_path_expander.rb +9 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fea80c4cff03e65125325d75b60a64e1e8fdfb2ae959483ea63fb1081decdc96
|
4
|
+
data.tar.gz: afbbf32a9ba9bffff56d42ecde177ac22411575276b45b70094a6ea026e6e9dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24a9797858c8a8b50a041d3a7855e30653ff0ce6c3c21086c9224e33bceb9feeb7dd14a4b38ab5789683b19cb17763e96bcdaf9b497d2e1a22ade78d3c7227e7
|
7
|
+
data.tar.gz: ce87766ab92c89098229bda19275ad41e54636e9d8a5b13605bbc46129c0e66d72793c6cf77421d0cf681806148e1af5cfeceb07d67f5be2044ea87154594a71
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
data/lib/path_expander.rb
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
# PathExpander.
|
14
14
|
|
15
15
|
class PathExpander
|
16
|
-
VERSION = "1.0
|
16
|
+
VERSION = "1.1.0" # :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
|
##
|
@@ -71,18 +78,25 @@ class PathExpander
|
|
71
78
|
# See expand_dirs_to_files for details on how expansion occurs.
|
72
79
|
#
|
73
80
|
# Subtraction happens last, regardless of argument ordering.
|
81
|
+
#
|
82
|
+
# If no files are found (which is not the same as having an empty
|
83
|
+
# file list after subtraction), then fall back to expanding on the
|
84
|
+
# default #path given to initialize.
|
74
85
|
|
75
86
|
def process_args
|
76
87
|
pos_files = []
|
77
88
|
neg_files = []
|
78
89
|
flags = []
|
90
|
+
clean = true
|
79
91
|
|
80
92
|
args.each do |arg|
|
81
93
|
case arg
|
82
94
|
when /^@(.*)/ then # push back on, so they can have dirs/-/@ as well
|
95
|
+
clean = false
|
83
96
|
args.concat process_file $1
|
84
97
|
when /^-(.*)/ then
|
85
98
|
if File.exist? $1 then
|
99
|
+
clean = false
|
86
100
|
neg_files += expand_dirs_to_files($1)
|
87
101
|
else
|
88
102
|
flags << arg
|
@@ -90,6 +104,7 @@ class PathExpander
|
|
90
104
|
else
|
91
105
|
root_path = File.expand_path(arg) == "/" # eg: -n /./
|
92
106
|
if File.exist? arg and not root_path then
|
107
|
+
clean = false
|
93
108
|
pos_files += expand_dirs_to_files(arg)
|
94
109
|
else
|
95
110
|
flags << arg
|
@@ -97,7 +112,10 @@ class PathExpander
|
|
97
112
|
end
|
98
113
|
end
|
99
114
|
|
100
|
-
|
115
|
+
files = pos_files - neg_files
|
116
|
+
files += expand_dirs_to_files(self.path) if files.empty? && clean
|
117
|
+
|
118
|
+
[files, flags]
|
101
119
|
end
|
102
120
|
|
103
121
|
##
|
data/test/test_path_expander.rb
CHANGED
@@ -24,7 +24,7 @@ class TestPathExpander < Minitest::Test
|
|
24
24
|
def assert_process_args exp_files, exp_args, *args
|
25
25
|
expander.args.concat args
|
26
26
|
|
27
|
-
assert_equal [exp_files, exp_args], expander.process_args
|
27
|
+
assert_equal [exp_files.sort, exp_args], expander.process_args
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_expand_dirs_to_files
|
@@ -157,6 +157,14 @@ class TestPathExpander < Minitest::Test
|
|
157
157
|
"/./")
|
158
158
|
end
|
159
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
|
+
|
160
168
|
def test_process_flags
|
161
169
|
exp = %w[a b c]
|
162
170
|
act = expander.process_flags %w[a b c]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: path_expander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Davis
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
Em82dBUFsipwMLCYj39kcyHWAxyl6Ae1Cn9r/ItVBCxoeFdrHjfavnrIEoXUt4bU
|
30
30
|
UfBugfLD19bu3nvL+zTAGx/U
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2019-09-
|
32
|
+
date: 2019-09-22 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: rdoc
|
metadata.gz.sig
CHANGED
Binary file
|