path_expander 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bb707e47c24f77a4b4a2d23c8db936f9b6d0b9db
4
+ data.tar.gz: f69d58051c1c4a8d38e7c762bf164cc4b2b96055
5
+ SHA512:
6
+ metadata.gz: c91cc5482ca821c474986e05cfc0d1b337f1cd9c2632fd323578e9f0a5e8789825204c9ebd748d26ca7b97bb184225555c96459724cfd1b6f88dbb43b3f1661f
7
+ data.tar.gz: 0b50d8770583b077005a75039a972ca2b7f1e1b4f766c8d0772f891b2a43972bc5157433a1ae51a1511de430d6538dfbe7a28197cb043b2e9bb7f67023e167cb
Binary file
Binary file
@@ -0,0 +1,26 @@
1
+ # -*- ruby -*-
2
+
3
+ require "autotest/restart"
4
+
5
+ Autotest.add_hook :initialize do |at|
6
+ at.testlib = "minitest/autorun"
7
+ at.add_exception "tmp"
8
+
9
+ # at.extra_files << "../some/external/dependency.rb"
10
+ #
11
+ # at.libs << ":../some/external"
12
+ #
13
+ # at.add_exception "vendor"
14
+ #
15
+ # at.add_mapping(/dependency.rb/) do |f, _|
16
+ # at.files_matching(/test_.*rb$/)
17
+ # end
18
+ #
19
+ # %w(TestA TestB).each do |klass|
20
+ # at.extra_class_map[klass] = "test/test_misc.rb"
21
+ # end
22
+ end
23
+
24
+ # Autotest.add_hook :run_command do |at|
25
+ # system "rake build"
26
+ # end
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2016-05-11
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,8 @@
1
+ .autotest
2
+ History.rdoc
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/path_expander.rb
7
+ test/test_bad.rb
8
+ test/test_path_expander.rb
@@ -0,0 +1,74 @@
1
+ = path_expander
2
+
3
+ home :: https://github.com/seattlerb/path_expander
4
+ rdoc :: http://docs.seattlerb.org/path_expander
5
+
6
+ == DESCRIPTION:
7
+
8
+ PathExpander helps pre-process command-line arguments expanding
9
+ directories into their constituent files. It further helps by
10
+ providing additional mechanisms to make specifying subsets easier
11
+ with path subtraction and allowing for command-line arguments to be
12
+ saved in a file.
13
+
14
+ NOTE: this is NOT an options processor. It is a path processor
15
+ (basically everything else besides options). It does provide a
16
+ mechanism for pre-filtering cmdline options, but not with the intent
17
+ of actually processing them in PathExpander. Use OptionParser to
18
+ deal with options either before or after passing ARGV through
19
+ PathExpander.
20
+
21
+ == FEATURES/PROBLEMS:
22
+
23
+ * Processes command-line arguments.
24
+ * Expands directories into files using custom globs.
25
+ * Allows for negation of files.
26
+ * Allows for use of files as persisted args.
27
+ * Provides a .ignore mechanism for lightweight persistent exclusion.
28
+
29
+ == SYNOPSIS:
30
+
31
+ class MyPathExpander < PathExpander
32
+ MY_GLOB = "**/*.rb"
33
+
34
+ def initialize args = ARGV
35
+ super args, TEST_GLOB
36
+ end
37
+ end
38
+
39
+ MyPathExpander.new(ARGV, my_glob).process.each do |f|
40
+ # do something with each file
41
+ end
42
+
43
+ == REQUIREMENTS:
44
+
45
+ * ruby
46
+
47
+ == INSTALL:
48
+
49
+ * sudo gem install path_expander
50
+
51
+ == LICENSE:
52
+
53
+ (The MIT License)
54
+
55
+ Copyright (c) Ryan Davis, seattle.rb
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining
58
+ a copy of this software and associated documentation files (the
59
+ 'Software'), to deal in the Software without restriction, including
60
+ without limitation the rights to use, copy, modify, merge, publish,
61
+ distribute, sublicense, and/or sell copies of the Software, and to
62
+ permit persons to whom the Software is furnished to do so, subject to
63
+ the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be
66
+ included in all copies or substantial portions of the Software.
67
+
68
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
69
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
70
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
71
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
72
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
73
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
74
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # -*- ruby -*-
2
+
3
+ require "rubygems"
4
+ require "hoe"
5
+
6
+ Hoe.plugin :isolate
7
+ Hoe.plugin :seattlerb
8
+ Hoe.plugin :rdoc
9
+
10
+ # Hoe.plugin :compiler
11
+ # Hoe.plugin :doofus
12
+ # Hoe.plugin :email
13
+ # Hoe.plugin :gem_prelude_sucks
14
+ # Hoe.plugin :history
15
+ # Hoe.plugin :inline
16
+ # Hoe.plugin :isolate
17
+ # Hoe.plugin :minitest
18
+ # Hoe.plugin :perforce
19
+ # Hoe.plugin :racc
20
+ # Hoe.plugin :rcov
21
+ # Hoe.plugin :rdoc
22
+ # Hoe.plugin :seattlerb
23
+
24
+ Hoe.spec "path_expander" do
25
+ developer "Ryan Davis", "ryand-ruby@zenspider.com"
26
+
27
+ license "MIT"
28
+ end
29
+
30
+ # vim: syntax=ruby
@@ -0,0 +1,165 @@
1
+ ##
2
+ # PathExpander helps pre-process command-line arguments expanding
3
+ # directories into their constituent files. It further helps by
4
+ # providing additional mechanisms to make specifying subsets easier
5
+ # with path subtraction and allowing for command-line arguments to be
6
+ # saved in a file.
7
+ #
8
+ # NOTE: this is NOT an options processor. It is a path processor
9
+ # (basically everything else besides options). It does provide a
10
+ # mechanism for pre-filtering cmdline options, but not with the intent
11
+ # of actually processing them in PathExpander. Use OptionParser to
12
+ # deal with options either before or after passing ARGV through
13
+ # PathExpander.
14
+
15
+ class PathExpander
16
+ VERSION = "1.0.0" # :nodoc:
17
+
18
+ ##
19
+ # The args array to process.
20
+
21
+ attr_accessor :args
22
+
23
+ ##
24
+ # The glob used to expand dirs to files.
25
+
26
+ attr_accessor :glob
27
+
28
+ ##
29
+ # Create a new path expander that operates on args and expands via
30
+ # glob as necessary.
31
+
32
+ def initialize args, glob
33
+ self.args = args
34
+ self.glob = glob
35
+ end
36
+
37
+ ##
38
+ # Takes an array of paths and returns an array of paths where all
39
+ # directories are expanded to all files found via the glob provided
40
+ # to PathExpander.
41
+
42
+ def expand_dirs_to_files *dirs
43
+ dirs.flatten.map { |p|
44
+ if File.directory? p then
45
+ Dir[File.join(p, glob)]
46
+ else
47
+ p
48
+ end
49
+ }.flatten
50
+ end
51
+
52
+ ##
53
+ # Process a file into more arguments. Override this to add
54
+ # additional capabilities.
55
+
56
+ def process_file path
57
+ File.readlines(path).map(&:chomp)
58
+ end
59
+
60
+ ##
61
+ # Enumerate over args passed to PathExpander and return a list of
62
+ # files and flags to process. Arguments are processed as:
63
+ #
64
+ # @file_of_args :: Read the file and append to args.
65
+ # -file_path :: Subtract path from file to be processed.
66
+ # -dir_path :: Expand and subtract paths from files to be processed.
67
+ # -not_a_path :: Add to flags to be processed.
68
+ # dir_path :: Expand and add to files to be processed.
69
+ # file_path :: Add to files to be processed.
70
+ #
71
+ # See expand_dirs_to_files for details on how expansion occurs.
72
+ #
73
+ # Subtraction happens last, regardless of argument ordering.
74
+
75
+ def process_args
76
+ pos_files = []
77
+ neg_files = []
78
+ flags = []
79
+
80
+ args.each do |arg|
81
+ case arg
82
+ when /^@(.*)/ then # push back on, so they can have dirs/-/@ as well
83
+ args.concat process_file $1
84
+ when /^-(.*)/ then
85
+ if File.exist? $1 then
86
+ neg_files += expand_dirs_to_files($1)
87
+ else
88
+ flags << arg
89
+ end
90
+ else
91
+ if File.exist? arg then
92
+ pos_files += expand_dirs_to_files(arg)
93
+ else
94
+ flags << arg
95
+ end
96
+ end
97
+ end
98
+
99
+ [pos_files - neg_files, flags]
100
+ end
101
+
102
+ ##
103
+ # Process over flags and treat any special ones here. Returns an
104
+ # array of the flags you haven't processed.
105
+ #
106
+ # This version does nothing. Subclass and override for
107
+ # customization.
108
+
109
+ def process_flags flags
110
+ flags
111
+ end
112
+
113
+ ##
114
+ # Top-level method processes args. It replaces args' contents with a
115
+ # new array of flags to process and returns a list of files to
116
+ # process. Eg
117
+ #
118
+ # PathExpander.new(ARGV).process.each do |f|
119
+ # puts "./#{f}"
120
+ # end
121
+
122
+ def process
123
+ files, flags = process_args
124
+
125
+ args.replace process_flags flags
126
+
127
+ files.uniq
128
+ end
129
+
130
+ ##
131
+ # A file filter mechanism similar to, but not as extensive as,
132
+ # .gitignore files:
133
+ #
134
+ # + If a pattern does not contain a slash, it is treated as a shell glob.
135
+ # + If a pattern ends in a slash, it matches on directories (and contents).
136
+ # + Otherwise, it matches on relative paths.
137
+ #
138
+ # File.fnmatch is used throughout, so glob patterns work for all 3 types.
139
+ #
140
+ # Takes a list of +files+ and either an io or path of +ignore+ data
141
+ # and returns a list of files left after filtering.
142
+
143
+ def filter_files files, ignore
144
+ ignore_paths = if ignore.respond_to? :read then
145
+ ignore.read
146
+ elsif File.exists? ignore then
147
+ File.read ignore
148
+ end
149
+
150
+ if ignore_paths then
151
+ nonglobs, globs = ignore_paths.split("\n").partition { |p| p.include? "/" }
152
+ dirs, ifiles = nonglobs.partition { |p| p.end_with? "/" }
153
+ dirs = dirs.map { |s| s.chomp "/" }
154
+
155
+ only_paths = File::FNM_PATHNAME
156
+ files = files.reject { |f|
157
+ dirs.any? { |i| File.fnmatch?(i, File.dirname(f), only_paths) } ||
158
+ globs.any? { |i| File.fnmatch?(i, f) } ||
159
+ ifiles.any? { |i| File.fnmatch?(i, f, only_paths) }
160
+ }
161
+ end
162
+
163
+ files
164
+ end
165
+ end
@@ -0,0 +1 @@
1
+ # ignore me. just for filtering
@@ -0,0 +1,131 @@
1
+ require "minitest/autorun"
2
+ require "path_expander"
3
+
4
+ class TestPathExpander < Minitest::Test
5
+ attr_accessor :args
6
+ attr_accessor :expander
7
+
8
+ def setup
9
+ self.args = []
10
+
11
+ self.expander = PathExpander.new args, "*.rb"
12
+ end
13
+
14
+ def assert_filter_files exp, filter, files = %w[test/dog_and_cat.rb]
15
+ ignore = StringIO.new filter
16
+ act = expander.filter_files files, ignore
17
+ assert_equal exp, act
18
+ end
19
+
20
+ def assert_process_args exp_files, exp_args, *args
21
+ expander.args.concat args
22
+
23
+ assert_equal [exp_files, exp_args], expander.process_args
24
+ end
25
+
26
+ def test_expand_dirs_to_files
27
+ exp = %w[test/test_bad.rb test/test_path_expander.rb]
28
+
29
+ assert_equal exp, expander.expand_dirs_to_files("test")
30
+ assert_equal %w[Rakefile], expander.expand_dirs_to_files("Rakefile")
31
+ end
32
+
33
+ def test_filter_files_dir
34
+ assert_filter_files [], "test/"
35
+ end
36
+
37
+ def test_filter_files_files
38
+ assert_filter_files [], "test/*.rb"
39
+
40
+ example = %w[test/file.rb test/sub/file.rb top/test/perf.rb]
41
+
42
+ assert_filter_files example[1..-1], "test/*.rb", example
43
+ end
44
+
45
+ def test_filter_files_glob
46
+ assert_filter_files [], "test*"
47
+ assert_filter_files [], "test*", ["test/lib/woot.rb"]
48
+ assert_filter_files [], "*.rb"
49
+ assert_filter_files [], "*dog*.rb"
50
+ end
51
+
52
+ def test_filter_files_glob_miss
53
+ miss = %w[test/dog_and_cat.rb]
54
+ assert_filter_files miss, "test"
55
+ assert_filter_files miss, "nope"
56
+ end
57
+
58
+ def test_process
59
+ self.args.concat %w[test --seed 42]
60
+
61
+ act = expander.process
62
+
63
+ assert_equal %w[test/test_bad.rb test/test_path_expander.rb], act
64
+ assert_equal %w[--seed 42], expander.args
65
+ assert_equal %w[--seed 42], args # affected our original array (eg, ARGV)
66
+ end
67
+
68
+ def with_tempfile *lines
69
+ require "tempfile"
70
+
71
+ Tempfile.open("tmp") do |f|
72
+ f.puts lines
73
+ f.flush
74
+ f.rewind
75
+
76
+ yield f
77
+ end
78
+ end
79
+
80
+ def test_process_args_at
81
+ with_tempfile %w[test -test/test_bad.rb --seed 24] do |f|
82
+ assert_process_args(%w[test/test_path_expander.rb],
83
+ %w[--seed 24],
84
+ "@#{f.path}")
85
+ end
86
+ end
87
+
88
+ def test_process_args_dash_dir
89
+ assert_process_args(%w[],
90
+ %w[],
91
+ "test", "-test")
92
+ end
93
+
94
+ def test_process_args_dash_file
95
+ assert_process_args(%w[test/test_path_expander.rb],
96
+ %w[],
97
+ "test", "-test/test_bad.rb")
98
+
99
+ end
100
+
101
+ def test_process_args_dash_other
102
+ assert_process_args(%w[],
103
+ %w[--verbose],
104
+ "--verbose")
105
+ end
106
+
107
+ def test_process_args_dir
108
+ assert_process_args(%w[test/test_bad.rb test/test_path_expander.rb],
109
+ %w[],
110
+ "test")
111
+ end
112
+
113
+ def test_process_args_file
114
+ assert_process_args(%w[test/test_path_expander.rb],
115
+ %w[],
116
+ "test/test_path_expander.rb")
117
+ end
118
+
119
+ def test_process_args_other
120
+ assert_process_args(%w[],
121
+ %w[42],
122
+ "42")
123
+ end
124
+
125
+ def test_process_flags
126
+ exp = %w[a b c]
127
+ act = expander.process_flags %w[a b c]
128
+
129
+ assert_equal exp, act
130
+ end
131
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: path_expander
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Davis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDPjCCAiagAwIBAgIBAzANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
14
+ ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
15
+ GRYDY29tMB4XDTE1MDkxOTIwNTEyMloXDTE2MDkxODIwNTEyMlowRTETMBEGA1UE
16
+ AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
17
+ JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
18
+ b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
19
+ taCPaLmfYIaFcHHCSY4hYDJijRQkLxPeB3xbOfzfLoBDbjvx5JxgJxUjmGa7xhcT
20
+ oOvjtt5P8+GSK9zLzxQP0gVLS/D0FmoE44XuDr3iQkVS2ujU5zZL84mMNqNB1znh
21
+ GiadM9GHRaDiaxuX0cIUBj19T01mVE2iymf9I6bEsiayK/n6QujtyCbTWsAS9Rqt
22
+ qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
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
31
+ -----END CERTIFICATE-----
32
+ date: 2016-05-13 00:00:00.000000000 Z
33
+ dependencies:
34
+ - !ruby/object:Gem::Dependency
35
+ name: rdoc
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: hoe
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.15'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.15'
62
+ description: |-
63
+ PathExpander helps pre-process command-line arguments expanding
64
+ directories into their constituent files. It further helps by
65
+ providing additional mechanisms to make specifying subsets easier
66
+ with path subtraction and allowing for command-line arguments to be
67
+ saved in a file.
68
+
69
+ NOTE: this is NOT an options processor. It is a path processor
70
+ (basically everything else besides options). It does provide a
71
+ mechanism for pre-filtering cmdline options, but not with the intent
72
+ of actually processing them in PathExpander. Use OptionParser to
73
+ deal with options either before or after passing ARGV through
74
+ PathExpander.
75
+ email:
76
+ - ryand-ruby@zenspider.com
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files:
80
+ - History.rdoc
81
+ - Manifest.txt
82
+ - README.rdoc
83
+ files:
84
+ - .autotest
85
+ - History.rdoc
86
+ - Manifest.txt
87
+ - README.rdoc
88
+ - Rakefile
89
+ - lib/path_expander.rb
90
+ - test/test_bad.rb
91
+ - test/test_path_expander.rb
92
+ homepage: https://github.com/seattlerb/path_expander
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options:
98
+ - --main
99
+ - README.rdoc
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.5
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: PathExpander helps pre-process command-line arguments expanding directories
118
+ into their constituent files
119
+ test_files: []
@@ -0,0 +1,3 @@
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��^�+��