recls-ruby 2.11.0 → 2.11.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/LICENSE +27 -24
- data/README.md +242 -1
- data/examples/find_files_and_directories.md +33 -30
- data/examples/find_files_and_directories.recursive.md +255 -254
- data/examples/show_hidden_files.md +4 -1
- data/examples/show_hidden_files.rb +1 -1
- data/examples/show_readonly_files.md +4 -1
- data/examples/show_readonly_files.rb +1 -1
- data/lib/recls/api.rb +75 -73
- data/lib/recls/combine_paths_1.rb +25 -23
- data/lib/recls/combine_paths_2plus.rb +31 -29
- data/lib/recls/entry.rb +276 -273
- data/lib/recls/file_search.rb +195 -193
- data/lib/recls/flags.rb +46 -45
- data/lib/recls/foreach.rb +103 -98
- data/lib/recls/obsolete.rb +80 -79
- data/lib/recls/recls.rb +16 -15
- data/lib/recls/stat.rb +136 -134
- data/lib/recls/util.rb +94 -92
- data/lib/recls/version.rb +17 -17
- data/lib/recls/ximpl/os.rb +45 -43
- data/lib/recls/ximpl/unix.rb +38 -35
- data/lib/recls/ximpl/util.rb +597 -596
- data/lib/recls/ximpl/windows.rb +139 -136
- data/lib/recls.rb +10 -9
- data/test/scratch/test_display_parts.rb +33 -33
- data/test/scratch/test_entry.rb +6 -6
- data/test/scratch/test_files_and_directories.rb +8 -8
- data/test/scratch/test_foreach.rb +10 -10
- data/test/scratch/test_module_function.rb +33 -33
- data/test/scratch/test_pattern_arrays.rb +5 -5
- data/test/scratch/test_show_dev_and_ino.rb +1 -1
- data/test/scratch/test_show_hidden.rb +3 -3
- data/test/unit/tc_recls_entries.rb +31 -31
- data/test/unit/tc_recls_entry.rb +19 -19
- data/test/unit/tc_recls_file_search.rb +32 -32
- data/test/unit/tc_recls_module.rb +25 -25
- data/test/unit/tc_recls_util.rb +161 -161
- data/test/unit/tc_recls_ximpl_util.rb +676 -676
- data/test/unit/test_all_separately.sh +1 -1
- data/test/unit/ts_all.rb +4 -4
- metadata +6 -6
data/lib/recls/foreach.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
#
|
2
|
-
# File:
|
1
|
+
# ######################################################################## #
|
2
|
+
# File: recls/foreach.rb
|
3
3
|
#
|
4
|
-
# Purpose:
|
4
|
+
# Purpose: Definition of Recls::foreach() utility function
|
5
5
|
#
|
6
|
-
# Created:
|
7
|
-
# Updated:
|
6
|
+
# Created: 22nd October 2014
|
7
|
+
# Updated: 20th April 2024
|
8
8
|
#
|
9
|
-
# Author:
|
9
|
+
# Author: Matthew Wilson
|
10
10
|
#
|
11
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
11
12
|
# Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
|
12
13
|
# All rights reserved.
|
13
14
|
#
|
@@ -33,7 +34,7 @@
|
|
33
34
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
34
35
|
# POSSIBILITY OF SUCH DAMAGE.
|
35
36
|
#
|
36
|
-
#
|
37
|
+
# ######################################################################## #
|
37
38
|
|
38
39
|
|
39
40
|
require 'recls/file_search'
|
@@ -45,98 +46,102 @@ class Object; end # :nodoc:
|
|
45
46
|
|
46
47
|
module Recls
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
49
|
+
private
|
50
|
+
# @!visibility private
|
51
|
+
class FileSearchLineEnumerator # :nodoc: all
|
52
|
+
|
53
|
+
include Enumerable
|
54
|
+
|
55
|
+
# @!visibility private
|
56
|
+
def initialize(fs)
|
57
|
+
|
58
|
+
@fs = fs
|
59
|
+
end
|
60
|
+
|
61
|
+
# @!visibility private
|
62
|
+
def each(&block)
|
63
|
+
|
64
|
+
@fs.each do |fe|
|
65
|
+
|
66
|
+
IO.readlines(fe).each_with_index do |line, index|
|
67
|
+
|
68
|
+
case block.arity
|
69
|
+
when 1
|
70
|
+
|
71
|
+
yield line
|
72
|
+
when 2
|
73
|
+
|
74
|
+
yield line, index
|
75
|
+
when 3
|
76
|
+
|
77
|
+
yield line, index, fe
|
78
|
+
else
|
79
|
+
|
80
|
+
raise ArgumentError, "block must take 1, 2, or 3 parameters - #{block.arity} given. (Perhaps you have applied each_with_index, which cannot be done to Recls.foreach)"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end # class FileSearchLineEnumerator
|
86
|
+
public
|
87
|
+
|
88
|
+
# Performs a recursive search and enumerates the lines of all files
|
89
|
+
# found
|
90
|
+
#
|
91
|
+
# === Signature
|
92
|
+
#
|
93
|
+
# * *Parameters:*
|
94
|
+
# - +searchable+ A searchable instance obtained from Recls::file_search() or Recls::file_rsearch()
|
95
|
+
# - +search_root+ (String, Recls::Entry) The root directory of the search. May be +nil+, in which case the current directory is assumed
|
96
|
+
# - +patterns+ (String, Array) The pattern(s) for which to search. May be +nil+, in which case Recls::WILDCARDS_ALL is assumed
|
97
|
+
# - +options+ (Hash) An options hash
|
98
|
+
# - +flags+ (Integer) Combination of flags (with behaviour as described below for the +flags+ option)
|
99
|
+
#
|
100
|
+
# * *Block:*
|
101
|
+
# An optional block that will be executed once for each line in each file
|
102
|
+
# found, where the block must take 1, 2, or 3 parameters, representing the
|
103
|
+
# line [ + file-line-index [ + entry ]]. If no block is given, an
|
104
|
+
# enumerator is returned.
|
105
|
+
#
|
106
|
+
# ==== Parameter Ordering
|
107
|
+
#
|
108
|
+
# The parameters may be expressed in any of the following permutations:
|
109
|
+
# - +searchable+
|
110
|
+
# - +search_root+, +patterns+, +flags+
|
111
|
+
# - +search_root+, +patterns+, +options+
|
112
|
+
#
|
113
|
+
# === Return
|
114
|
+
#
|
115
|
+
def self.foreach(*args, &block)
|
116
|
+
|
117
|
+
fs = nil
|
118
|
+
|
119
|
+
case args.length
|
120
|
+
when 1
|
121
|
+
|
122
|
+
raise ArgumentError "Single argument must be of type #{Recls::FileSearch}" unless args[0].kind_of? Recls::FileSearch
|
123
|
+
|
124
|
+
fs = args[0]
|
125
|
+
when 3
|
126
|
+
|
127
|
+
fs = Recls::FileSearch.new(args[0], args[1], args[2])
|
128
|
+
else
|
129
|
+
|
130
|
+
raise ArgumentError "Function requires single argument (#{Recls::FileSearch}) or three arguments (directory, patterns, flags)"
|
131
|
+
end
|
132
|
+
|
133
|
+
if block_given?
|
134
|
+
|
135
|
+
FileSearchLineEnumerator.new(fs).each(block)
|
136
|
+
|
137
|
+
return nil
|
138
|
+
else
|
139
|
+
|
140
|
+
return FileSearchLineEnumerator.new(fs)
|
141
|
+
end
|
142
|
+
end
|
138
143
|
end # module Recls
|
139
144
|
|
140
|
-
# ############################## end of file ############################# #
|
141
145
|
|
146
|
+
# ############################## end of file ############################# #
|
142
147
|
|
data/lib/recls/obsolete.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
#
|
2
|
-
# File:
|
1
|
+
# ######################################################################## #
|
2
|
+
# File: recls/obsolete.rb
|
3
3
|
#
|
4
|
-
# Purpose:
|
4
|
+
# Purpose: Obsolete elements
|
5
5
|
#
|
6
|
-
# Created:
|
7
|
-
# Updated:
|
6
|
+
# Created: 19th July 2012
|
7
|
+
# Updated: 20th April 2024
|
8
8
|
#
|
9
|
-
# Author:
|
9
|
+
# Author: Matthew Wilson
|
10
10
|
#
|
11
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
11
12
|
# Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
|
12
13
|
# All rights reserved.
|
13
14
|
#
|
@@ -33,87 +34,87 @@
|
|
33
34
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
34
35
|
# POSSIBILITY OF SUCH DAMAGE.
|
35
36
|
#
|
36
|
-
#
|
37
|
+
# ######################################################################## #
|
37
38
|
|
38
39
|
|
39
40
|
|
40
|
-
#
|
41
|
+
# ######################################################################## #
|
41
42
|
# Obsolete symbols
|
42
43
|
|
43
44
|
if not defined? RECLS_NO_OBSOLETE
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
46
|
+
module Recls # :nodoc: all
|
47
|
+
|
48
|
+
# @!visibility private
|
49
|
+
def self.pathNameSeparator
|
50
|
+
|
51
|
+
PATH_NAME_SEPARATOR
|
52
|
+
end
|
53
|
+
|
54
|
+
# @!visibility private
|
55
|
+
def self.pathSeparator
|
56
|
+
|
57
|
+
PATH_SEPARATOR
|
58
|
+
end
|
59
|
+
|
60
|
+
# @!visibility private
|
61
|
+
def self.wildcardsAll
|
62
|
+
|
63
|
+
WILDCARDS_ALL
|
64
|
+
end
|
65
|
+
|
66
|
+
class FileSearch # :nodoc:
|
67
|
+
|
68
|
+
# @!visibility private
|
69
|
+
alias_method :searchRoot, :search_root
|
70
|
+
# @!visibility private
|
71
|
+
alias_method :pattern, :patterns
|
72
|
+
end
|
73
|
+
|
74
|
+
class Entry # :nodoc:
|
75
|
+
|
76
|
+
# @!visibility private
|
77
|
+
alias_method :uncDrive, :drive
|
78
|
+
# @!visibility private
|
79
|
+
alias_method :directoryPath, :directory_path
|
80
|
+
# @!visibility private
|
81
|
+
alias_method :directoryParts, :directory_parts
|
82
|
+
# @!visibility private
|
83
|
+
alias_method :file, :file_full_name
|
84
|
+
# @!visibility private
|
85
|
+
alias_method :shortFile, :file_short_name
|
86
|
+
# @!visibility private
|
87
|
+
alias_method :fileBaseName, :file_name_only
|
88
|
+
# @!visibility private
|
89
|
+
alias_method :fileName, :file_name_only
|
90
|
+
# @!visibility private
|
91
|
+
alias_method :fileExt, :file_extension
|
92
|
+
# @!visibility private
|
93
|
+
alias_method :searchDirectory, :search_directory
|
94
|
+
# @!visibility private
|
95
|
+
alias_method :searchRelativePath, :search_relative_path
|
96
|
+
|
97
|
+
# @!visibility private
|
98
|
+
alias_method :isDirectory, :directory?
|
99
|
+
# @!visibility private
|
100
|
+
alias_method :isFile, :file?
|
101
|
+
#alias_method :isLink, :link?
|
102
|
+
# @!visibility private
|
103
|
+
alias_method :isReadOnly, :readonly?
|
104
|
+
# @!visibility private
|
105
|
+
def isUNC
|
106
|
+
|
107
|
+
d = drive
|
108
|
+
|
109
|
+
d and d.size > 2
|
110
|
+
end
|
111
|
+
|
112
|
+
# @!visibility private
|
113
|
+
alias_method :creationTime, :modification_time
|
114
|
+
end
|
115
|
+
end # module Recls
|
115
116
|
end
|
116
117
|
|
117
|
-
# ############################## end of file ############################# #
|
118
118
|
|
119
|
+
# ############################## end of file ############################# #
|
119
120
|
|
data/lib/recls/recls.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
#
|
2
|
-
# File:
|
1
|
+
# ######################################################################## #
|
2
|
+
# File: recls/recls.rb
|
3
3
|
#
|
4
|
-
# Purpose:
|
4
|
+
# Purpose: Main source file for recls library
|
5
5
|
#
|
6
|
-
# Created:
|
7
|
-
# Updated:
|
6
|
+
# Created: 19th July 2012
|
7
|
+
# Updated: 20th April 2024
|
8
8
|
#
|
9
|
-
# Author:
|
9
|
+
# Author: Matthew Wilson
|
10
10
|
#
|
11
|
+
# Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
|
11
12
|
# Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
|
12
13
|
# All rights reserved.
|
13
14
|
#
|
@@ -33,7 +34,7 @@
|
|
33
34
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
34
35
|
# POSSIBILITY OF SUCH DAMAGE.
|
35
36
|
#
|
36
|
-
#
|
37
|
+
# ######################################################################## #
|
37
38
|
|
38
39
|
|
39
40
|
require 'recls/version'
|
@@ -67,19 +68,19 @@ end # module Recls
|
|
67
68
|
|
68
69
|
module Recls
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
# Represents the "all" wildcards string for the ambient operating
|
72
|
+
# system
|
73
|
+
WILDCARDS_ALL = Recls::Ximpl::OS::WILDCARDS_ALL
|
73
74
|
|
74
|
-
|
75
|
-
|
75
|
+
# The string sequence used to separate names in paths, e.g. "/" on UNIX
|
76
|
+
PATH_NAME_SEPARATOR = Recls::Ximpl::OS::PATH_NAME_SEPARATOR
|
76
77
|
|
77
|
-
|
78
|
-
|
78
|
+
# The string sequence used to separate paths, e.g. ":" on UNIX
|
79
|
+
PATH_SEPARATOR = Recls::Ximpl::OS::PATH_SEPARATOR
|
79
80
|
end # module Recls
|
80
81
|
|
81
82
|
require 'recls/obsolete'
|
82
83
|
|
83
|
-
# ############################## end of file ############################# #
|
84
84
|
|
85
|
+
# ############################## end of file ############################# #
|
85
86
|
|