path_expander-1.1.3/0000755000004100000410000000000014716762605014404 5ustar www-datawww-datapath_expander-1.1.3/Manifest.txt0000444000004100000410000000023014716762605016704 0ustar www-datawww-data.autotest History.rdoc Manifest.txt README.rdoc Rakefile lib/path_expander.rb test/bad_named_dir.rb/.ignore test/test_bad.rb test/test_path_expander.rb path_expander-1.1.3/.autotest0000444000004100000410000000104014716762605016246 0ustar www-datawww-data# -*- ruby -*- require "autotest/restart" Autotest.add_hook :initialize do |at| at.testlib = "minitest/autorun" at.add_exception "tmp" # at.extra_files << "../some/external/dependency.rb" # # at.libs << ":../some/external" # # at.add_exception "vendor" # # at.add_mapping(/dependency.rb/) do |f, _| # at.files_matching(/test_.*rb$/) # end # # %w(TestA TestB).each do |klass| # at.extra_class_map[klass] = "test/test_misc.rb" # end end # Autotest.add_hook :run_command do |at| # system "rake build" # end path_expander-1.1.3/path_expander.gemspec0000644000004100000410000000706214716762605020600 0ustar www-datawww-data######################################################### # This file has been automatically generated by gem2tgz # ######################################################### # -*- encoding: utf-8 -*- # stub: path_expander 1.1.3 ruby lib Gem::Specification.new do |s| s.name = "path_expander".freeze s.version = "1.1.3" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.metadata = { "homepage_uri" => "https://github.com/seattlerb/path_expander" } if s.respond_to? :metadata= s.require_paths = ["lib".freeze] s.authors = ["Ryan Davis".freeze] s.cert_chain = ["-----BEGIN CERTIFICATE-----\nMIIDPjCCAiagAwIBAgIBCDANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu\nZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB\nGRYDY29tMB4XDTI0MDEwMjIxMjEyM1oXDTI1MDEwMTIxMjEyM1owRTETMBEGA1UE\nAwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS\nJomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda\nb9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx\ntaCPaLmfYIaFcHHCSY4hYDJijRQkLxPeB3xbOfzfLoBDbjvx5JxgJxUjmGa7xhcT\noOvjtt5P8+GSK9zLzxQP0gVLS/D0FmoE44XuDr3iQkVS2ujU5zZL84mMNqNB1znh\nGiadM9GHRaDiaxuX0cIUBj19T01mVE2iymf9I6bEsiayK/n6QujtyCbTWsAS9Rqt\nqhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV\ngBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw\nHQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBCwUAA4IB\nAQCygvpmncmkiSs9r/Kceo4bBPDszhTv6iBi4LwMReqnFrpNLMOWJw7xi8x+3eL2\nXS09ZPNOt2zm70KmFouBMgOysnDY4k2dE8uF6B8JbZOO8QfalW+CoNBliefOTcn2\nbg5IOP7UoGM5lC174/cbDJrJnRG9bzig5FAP0mvsgA8zgTRXQzIUAZEo92D5K7p4\nB4/O998ho6BSOgYBI9Yk1ttdCtti6Y+8N9+fZESsjtWMykA+WXWeGUScHqiU+gH8\nS7043fq9EbQdBr2AXdj92+CDwuTfHI6/Hj5FVBDULufrJaan4xUgL70Hvc6pTTeW\ndeKfBjgVAq7EYHu1AczzlUly\n-----END CERTIFICATE-----\n".freeze] s.date = "2024-09-11" s.description = "PathExpander helps pre-process command-line arguments expanding\ndirectories into their constituent files. It further helps by\nproviding additional mechanisms to make specifying subsets easier\nwith path subtraction and allowing for command-line arguments to be\nsaved in a file.\n\nNOTE: this is NOT an options processor. It is a path processor\n(basically everything else besides options). It does provide a\nmechanism for pre-filtering cmdline options, but not with the intent\nof actually processing them in PathExpander. Use OptionParser to\ndeal with options either before or after passing ARGV through\nPathExpander.".freeze s.email = ["ryand-ruby@zenspider.com".freeze] s.extra_rdoc_files = ["History.rdoc".freeze, "Manifest.txt".freeze, "README.rdoc".freeze] s.files = [".autotest".freeze, "History.rdoc".freeze, "Manifest.txt".freeze, "README.rdoc".freeze, "Rakefile".freeze, "lib/path_expander.rb".freeze, "test/bad_named_dir.rb/.ignore".freeze, "test/test_bad.rb".freeze, "test/test_path_expander.rb".freeze] s.homepage = "https://github.com/seattlerb/path_expander".freeze s.licenses = ["MIT".freeze] s.rdoc_options = ["--main".freeze, "README.rdoc".freeze] s.rubygems_version = "3.3.15".freeze s.summary = "PathExpander helps pre-process command-line arguments expanding directories into their constituent files".freeze if s.respond_to? :specification_version then s.specification_version = 4 end if s.respond_to? :add_runtime_dependency then s.add_development_dependency(%q.freeze, ["~> 4.2"]) s.add_development_dependency(%q.freeze, [">= 4.0", "< 7"]) else s.add_dependency(%q.freeze, ["~> 4.2"]) s.add_dependency(%q.freeze, [">= 4.0", "< 7"]) end end path_expander-1.1.3/README.rdoc0000444000004100000410000000460614716762605016216 0ustar www-datawww-data= path_expander home :: https://github.com/seattlerb/path_expander rdoc :: http://docs.seattlerb.org/path_expander == DESCRIPTION: PathExpander helps pre-process command-line arguments expanding directories into their constituent files. It further helps by providing additional mechanisms to make specifying subsets easier with path subtraction and allowing for command-line arguments to be saved in a file. NOTE: this is NOT an options processor. It is a path processor (basically everything else besides options). It does provide a mechanism for pre-filtering cmdline options, but not with the intent of actually processing them in PathExpander. Use OptionParser to deal with options either before or after passing ARGV through PathExpander. == FEATURES/PROBLEMS: * Processes command-line arguments. * Expands directories into files using custom globs. * Allows for negation of files. * Allows for use of files as persisted args. * Provides a .ignore mechanism for lightweight persistent exclusion. == SYNOPSIS: class MyPathExpander < PathExpander MY_GLOB = "**/*.rb" def initialize args = ARGV super args, MY_GLOB end end MyPathExpander.new(ARGV, my_glob).process.each do |f| # do something with each file end == REQUIREMENTS: * ruby == INSTALL: * sudo gem install path_expander == LICENSE: (The MIT License) Copyright (c) Ryan Davis, seattle.rb Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. path_expander-1.1.3/lib/0000755000004100000410000000000014716762605015152 5ustar www-datawww-datapath_expander-1.1.3/lib/path_expander.rb0000444000004100000410000001303514716762605020321 0ustar www-datawww-data## # PathExpander helps pre-process command-line arguments expanding # directories into their constituent files. It further helps by # providing additional mechanisms to make specifying subsets easier # with path subtraction and allowing for command-line arguments to be # saved in a file. # # NOTE: this is NOT an options processor. It is a path processor # (basically everything else besides options). It does provide a # mechanism for pre-filtering cmdline options, but not with the intent # of actually processing them in PathExpander. Use OptionParser to # deal with options either before or after passing ARGV through # PathExpander. class PathExpander VERSION = "1.1.3" # :nodoc: ## # The args array to process. attr_accessor :args ## # The glob used to expand dirs to files. attr_accessor :glob ## # The path to scan if no paths are found in the initial scan. attr_accessor :path ## # Create a new path expander that operates on args and expands via # glob as necessary. Takes an optional +path+ arg to fall back on if # no paths are found on the initial scan (see #process_args). def initialize args, glob, path = "." self.args = args self.glob = glob self.path = path end ## # Takes an array of paths and returns an array of paths where all # directories are expanded to all files found via the glob provided # to PathExpander. # # Paths are normalized to not have a leading "./". def expand_dirs_to_files *dirs dirs.flatten.map { |p| if File.directory? p then Dir[File.join(p, glob)].find_all { |f| File.file? f } else p end }.flatten.sort.map { |s| s.to_s.delete_prefix "./" } end ## # Process a file into more arguments. Override this to add # additional capabilities. def process_file path File.readlines(path).map(&:chomp) end ## # Enumerate over args passed to PathExpander and return a list of # files and flags to process. Arguments are processed as: # # @file_of_args :: Read the file and append to args. # -file_path :: Subtract path from file to be processed. # -dir_path :: Expand and subtract paths from files to be processed. # -not_a_path :: Add to flags to be processed. # dir_path :: Expand and add to files to be processed. # file_path :: Add to files to be processed. # - :: Add "-" (stdin) to files to be processed. # # See expand_dirs_to_files for details on how expansion occurs. # # Subtraction happens last, regardless of argument ordering. # # If no files are found (which is not the same as having an empty # file list after subtraction), then fall back to expanding on the # default #path given to initialize. def process_args pos_files = [] neg_files = [] flags = [] clean = true args.each do |arg| case arg when /^@(.*)/ then # push back on, so they can have dirs/-/@ as well clean = false args.concat process_file $1 when "-" then pos_files << arg when /^-(.*)/ then if File.exist? $1 then clean = false neg_files += expand_dirs_to_files($1) else flags << arg end else root_path = File.expand_path(arg) == "/" # eg: -n /./ if File.exist? arg and not root_path then clean = false pos_files += expand_dirs_to_files(arg) else flags << arg end end end files = pos_files - neg_files files += expand_dirs_to_files(self.path) if files.empty? && clean [files, flags] end ## # Process over flags and treat any special ones here. Returns an # array of the flags you haven't processed. # # This version does nothing. Subclass and override for # customization. def process_flags flags flags end ## # Top-level method processes args. It replaces args' contents with a # new array of flags to process and returns a list of files to # process. Eg # # PathExpander.new(ARGV).process.each do |f| # puts "./#{f}" # end def process files, flags = process_args args.replace process_flags flags files.uniq end ## # A file filter mechanism similar to, but not as extensive as, # .gitignore files: # # + If a pattern does not contain a slash, it is treated as a shell glob. # + If a pattern ends in a slash, it matches on directories (and contents). # + Otherwise, it matches on relative paths. # # File.fnmatch is used throughout, so glob patterns work for all 3 types. # # Takes a list of +files+ and either an io or path of +ignore+ data # and returns a list of files left after filtering. def filter_files files, ignore ignore_paths = if ignore.respond_to? :read then ignore.read elsif File.exist? ignore then File.read ignore end if ignore_paths then nonglobs, globs = ignore_paths.split("\n").partition { |p| p.include? "/" } dirs, ifiles = nonglobs.partition { |p| p.end_with? "/" } dirs = dirs.map { |s| s.chomp "/" } dirs.map! { |i| File.expand_path i } globs.map! { |i| File.expand_path i } ifiles.map! { |i| File.expand_path i } only_paths = File::FNM_PATHNAME files = files.reject { |f| f = File.expand_path(f) dirs.any? { |i| File.fnmatch?(i, File.dirname(f), only_paths) } || globs.any? { |i| File.fnmatch?(i, f) } || ifiles.any? { |i| File.fnmatch?(i, f, only_paths) } } end files end end path_expander-1.1.3/test/0000755000004100000410000000000014716762605015363 5ustar www-datawww-datapath_expander-1.1.3/test/bad_named_dir.rb/0000755000004100000410000000000014716762605020515 5ustar www-datawww-datapath_expander-1.1.3/test/bad_named_dir.rb/.ignore0000444000004100000410000000000014716762605021765 0ustar www-datawww-datapath_expander-1.1.3/test/test_bad.rb0000444000004100000410000000004014716762605017465 0ustar www-datawww-data# ignore me. just for filtering path_expander-1.1.3/test/test_path_expander.rb0000444000004100000410000001175214716762605021575 0ustar www-datawww-datarequire "minitest/autorun" require "path_expander" class TestPathExpander < Minitest::Test attr_accessor :args attr_accessor :expander def setup self.args = [] self.expander = PathExpander.new args, "*.rb" end def assert_filter_files exp, filter, files = %w[test/dog_and_cat.rb] ignore = StringIO.new filter act = expander.filter_files files, ignore assert_equal exp, act end def assert_filter_files_absolute_paths exp, filter, files = [File.join(Dir.pwd, 'test/dog_and_cat.rb')] assert_filter_files exp, filter, files end def assert_process_args exp_files, exp_args, *args expander.args.concat args assert_equal [exp_files.sort, exp_args], expander.process_args end def test_expand_dirs_to_files exp = %w[test/test_bad.rb test/test_path_expander.rb] assert_equal exp, expander.expand_dirs_to_files("test") assert_equal %w[Rakefile], expander.expand_dirs_to_files("Rakefile") end def test_expand_dirs_to_files__sorting exp = %w[test/test_bad.rb test/test_path_expander.rb] input = %w[test/test_path_expander.rb test/test_bad.rb] assert_equal exp, expander.expand_dirs_to_files(*input) assert_equal %w[Rakefile], expander.expand_dirs_to_files("Rakefile") end def test_expand_dirs_to_files__leading_dot exp = %w[test/test_bad.rb test/test_path_expander.rb] assert_equal exp, expander.expand_dirs_to_files("./test") end def test_filter_files_dir assert_filter_files [], "test/" assert_filter_files_absolute_paths [], "test/" end def test_filter_files_files example = %w[test/file.rb test/sub/file.rb top/test/perf.rb] example_absolute_paths = example.map { |e| File.join(Dir.pwd, e) } assert_filter_files [], "test/*.rb" assert_filter_files example[1..-1], "test/*.rb", example assert_filter_files_absolute_paths [], "test/*.rb" assert_filter_files_absolute_paths example_absolute_paths[1..-1], "test/*.rb", example_absolute_paths end def test_filter_files_glob assert_filter_files [], "test*" assert_filter_files [], "test*", ["test/lib/woot.rb"] assert_filter_files [], "*.rb" assert_filter_files [], "*dog*.rb" assert_filter_files_absolute_paths [], "test*" assert_filter_files_absolute_paths [], "test*", [File.join(Dir.pwd, "test/lib/woot.rb")] assert_filter_files_absolute_paths [], "*.rb" assert_filter_files_absolute_paths [], "*dog*.rb" end def test_filter_files_glob_miss miss = %w[test/dog_and_cat.rb] miss_absolute = [File.join(Dir.pwd, 'test/dog_and_cat.rb')] assert_filter_files miss, "test" assert_filter_files miss, "nope" assert_filter_files_absolute_paths miss_absolute, "test" assert_filter_files_absolute_paths miss_absolute, "nope" end def test_process self.args.concat %w[test --seed 42] act = expander.process assert_equal %w[test/test_bad.rb test/test_path_expander.rb], act assert_equal %w[--seed 42], expander.args assert_equal %w[--seed 42], args # affected our original array (eg, ARGV) end def with_tempfile *lines require "tempfile" Tempfile.open("tmp") do |f| f.puts lines f.flush f.rewind yield f end end def test_process_args_at with_tempfile %w[test -test/test_bad.rb --seed 24] do |f| assert_process_args(%w[test/test_path_expander.rb], %w[--seed 24], "@#{f.path}") end end def test_process_args_dash_dir assert_process_args(%w[], %w[], "test", "-test") end def test_process_args_dash_file assert_process_args(%w[test/test_path_expander.rb], %w[], "test", "-test/test_bad.rb") end def test_process_args_dash_other assert_process_args(%w[], %w[--verbose], "--verbose") end def test_process_args_dir assert_process_args(%w[test/test_bad.rb test/test_path_expander.rb], %w[], "test") end def test_process_args_file assert_process_args(%w[test/test_path_expander.rb], %w[], "test/test_path_expander.rb") end def test_process_args_other assert_process_args(%w[], %w[42], "42") end def test_process_args_root assert_process_args(%w[], %w[-n /./], "-n", "/./") end def test_process_args_no_files self.expander = PathExpander.new args, "*.rb", "test" # extra test default assert_process_args(%w[test/test_bad.rb test/test_path_expander.rb], %w[-v], "-v") end def test_process_args_dash assert_process_args(%w[-], %w[-v], "-", "-v") end def test_process_flags exp = %w[a b c] act = expander.process_flags %w[a b c] assert_equal exp, act end end path_expander-1.1.3/checksums.yaml.gz.sig0000444000004100000410000000040014716762605020445 0ustar www-datawww-dataƪ48N}k8(7^28E?_wHvqhF-bFQ2I,(/ ==нemoHqubHf)`,4x"Q67G{5^1/.ʵ.. 9l)2A dNtɖsfHG|90v-ɋ#E`Ѯ Y+~f@=-path_expander-1.1.3/Rakefile0000444000004100000410000000101114716762605016040 0ustar www-datawww-data# -*- ruby -*- require "rubygems" require "hoe" Hoe.plugin :isolate Hoe.plugin :seattlerb Hoe.plugin :rdoc # Hoe.plugin :compiler # Hoe.plugin :doofus # Hoe.plugin :email # Hoe.plugin :gem_prelude_sucks # Hoe.plugin :history # Hoe.plugin :inline # Hoe.plugin :isolate # Hoe.plugin :minitest # Hoe.plugin :perforce # Hoe.plugin :racc # Hoe.plugin :rcov # Hoe.plugin :rdoc # Hoe.plugin :seattlerb Hoe.spec "path_expander" do developer "Ryan Davis", "ryand-ruby@zenspider.com" license "MIT" end # vim: syntax=ruby path_expander-1.1.3/data.tar.gz.sig0000444000004100000410000000040014716762605017215 0ustar www-datawww-dataˠӀӣ(89H?вxұ*qF_'PjY@Bξf4ae_hQJmt*X FfHxIT9r$Ry8K:rKW|ܖV)&j^9/*txc=9ᾘUyk(B{MCb\`ȡ npx^c^=yĭLR'2"q5p;=-G^nbYU%path_expander-1.1.3/History.rdoc0000444000004100000410000000212314716762605016712 0ustar www-datawww-data=== 1.1.3 / 2024-09-11 * 1 bug fix: * Call to_s before delete_prefix. Maybe don't pass Pathname objects to things that process ARGV? === 1.1.2 / 2024-07-11 * 1 bug fix: * Normalize './' off the front of all paths so options like '.' and '-test' work together better === 1.1.1 / 2022-07-03 * 1 bug fix: * Process plain '-' as a file, not an option. === 1.1.0 / 2019-09-22 * 1 minor enhancement: * Added a default path (default: ".") to scan if no files are initially found. === 1.0.5 / 2019-09-14 * 1 bug fix: * Fixed a deprecation warning from File.exists? === 1.0.4 / 2019-05-26 * 1 bug fix: * Sorted the output from expand_dirs_to_files. (deivid-rodriguez) === 1.0.3 / 2018-03-16 * 1 bug fix: * Don't process files if path expands to root directory. Prevents -n /./ from hanging. === 1.0.2 / 2017-05-09 * 1 bug fix: * Fixed expand_dirs_to_files returning non-files on glob expansion. === 1.0.1 / 2016-11-30 * 1 bug fix: * Expanded paths in filter_files to fix globs w/ absolute paths. (mknapik) === 1.0.0 / 2016-05-11 * 1 major enhancement * Birthday! path_expander-1.1.3/metadata.gz.sig0000444000004100000410000000040014716762605017277 0ustar www-datawww-dataP|'\0qwa7ya35J\KnIlEŬ,2Lmɶ*lS3G+Y*l2:TMw do{6<3Ͻ;? ;Fppne]aupqUr{ᏮS E1+ocsHЪhI^L=