recls-ruby 2.8.2 → 2.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd3873b6ab2b854777d003cfefd78240322da3ec
4
- data.tar.gz: 35234197d743227278a98b4bb6d645f5c895a452
3
+ metadata.gz: c02ac6f3a48f84776ec957cd2642d9b910e5169d
4
+ data.tar.gz: 3d0b3e9eaffeb82e499279e32befa7ade72bc75f
5
5
  SHA512:
6
- metadata.gz: 62d7e2ee09b3b4ed8f8908a4ecbc5fb4c82b3c0cc6c553310913384c4573bebca95a8dd6c960f57c7555511fc954541c6542ef11a5d328cd4abed411ccae2689
7
- data.tar.gz: a7609496ada38d41d30b054603fbf28300961eae8f3b18012ab3ff68ac41d294b378a32c2d3093e50065bd1ee783b9287dac4f70cb5d5d709d7ad8ee0ebc3136
6
+ metadata.gz: 7f7229fff4e86c2653b0652fdc617824a84aa7a47ac9dbeedfc70523b5bb937b5d182e60f147edb0cf77aeffbdc32027d59474ce7d2f94a41d28e13d52db9ec4
7
+ data.tar.gz: f30f716243c9b9a19dcf3052561055fc80e89a325368bf8e9058efbb90a2842f7267f78017834a7209c6d6c284ae24a530f7f9cf6869997e26e3aeb8d7096933
data/lib/recls.rb CHANGED
@@ -39,3 +39,5 @@
39
39
  require 'recls/recls'
40
40
 
41
41
  # ############################## end of file ############################# #
42
+
43
+
data/lib/recls/api.rb CHANGED
@@ -4,11 +4,11 @@
4
4
  # Purpose: Defines Recls module search functions
5
5
  #
6
6
  # Created: 9th June 2016
7
- # Updated: 9th June 2016
7
+ # Updated: 21st March 2019
8
8
  #
9
9
  # Author: Matthew Wilson
10
10
  #
11
- # Copyright (c) 2016, Matthew Wilson and Synesis Software
11
+ # Copyright (c) 2016-2019, Matthew Wilson and Synesis Software
12
12
  # All rights reserved.
13
13
  #
14
14
  # Redistribution and use in source and binary forms, with or without
@@ -37,13 +37,95 @@
37
37
 
38
38
 
39
39
  require 'recls/file_search'
40
+ require 'recls/flags'
40
41
 
41
42
  module Recls
42
43
 
44
+ # [DEPRECATED] Use +Recls.file_search()+
45
+ #
46
+ # @deprecated
43
47
  def self.FileSearch(search_root, patterns, options = {})
44
48
 
45
49
  Recls::FileSearch.new(search_root, patterns, options)
46
50
  end
51
+
52
+ # Initialises a +FileSearch+ instance, which acts recursively, as an
53
+ # +Enumerable+ of Recls::Entry
54
+ #
55
+ # === Signature
56
+ #
57
+ # * *Parameters:*
58
+ # - +search_root+:: (String, Recls::Entry) The root directory of
59
+ # the search. May be +nil+, in which case the current directory
60
+ # is assumed
61
+ # - +patterns+:: (String, Array) The pattern(s) for which to
62
+ # search. May be +nil+, in which case +Recls::WILDCARDS_ALL+ is
63
+ # assumed
64
+ # - +options+:: (Hash, Integer) Combination of flags (with
65
+ # behaviour as described below for the +flags+ option), or an
66
+ # options hash
67
+ #
68
+ # * *Options:*
69
+ # - +flags+:: (Integer) Combination of flags - FILES,
70
+ # DIRECTORIES, etc. If the value modulo TYPEMASK is 0,
71
+ # then FILES is assumed. The value RECURSIVE is added by the
72
+ # function, and so need not be added by the caller; it cannot be
73
+ # removed
74
+ #
75
+ # === Return
76
+ # An instance of +::Recls::FileSearch+
77
+ #
78
+ def self.file_rsearch(search_root, patterns, options = {})
79
+
80
+ case options
81
+ when ::NilClass
82
+
83
+ options = { flags: RECURSIVE }
84
+ when ::Integer
85
+
86
+ options |= RECURSIVE
87
+ when ::Hash
88
+
89
+ flags = options[:flags] || 0
90
+ flags |= RECURSIVE
91
+
92
+ options[:flags] = flags
93
+ else
94
+
95
+ # this is handled by the FileSearch initialiser
96
+ end
97
+
98
+ Recls::FileSearch.new(search_root, patterns, options)
99
+ end
100
+
101
+ # Initialises a +FileSearch+ instance, which acts as an +Enumerable+
102
+ # of Recls::Entry
103
+ #
104
+ # === Signature
105
+ #
106
+ # * *Parameters:*
107
+ # - +search_root+:: (String, Recls::Entry) The root directory of
108
+ # the search. May be +nil+, in which case the current directory
109
+ # is assumed
110
+ # - +patterns+:: (String, Array) The pattern(s) for which to
111
+ # search. May be +nil+, in which case +Recls::WILDCARDS_ALL+ is
112
+ # assumed
113
+ # - +options+:: (Hash, Integer) Combination of flags (with
114
+ # behaviour as described below for the +flags+ option), or an
115
+ # options hash
116
+ #
117
+ # * *Options:*
118
+ # - +flags+:: (Integer) Combination of flags - FILES,
119
+ # DIRECTORIES, RECURSIVE, etc. If the value modulo TYPEMASK is 0,
120
+ # then FILES is assumed
121
+ #
122
+ # === Return
123
+ # An instance of +::Recls::FileSearch+
124
+ #
125
+ def self.file_search(search_root, patterns, options = {})
126
+
127
+ Recls::FileSearch.new(search_root, patterns, options)
128
+ end
47
129
  end
48
130
 
49
131
  # ############################## end of file ############################# #
@@ -0,0 +1,66 @@
1
+ # ######################################################################### #
2
+ # File: recls/compare_paths_1.rb
3
+ #
4
+ # Purpose: Definition of Recls::compare_paths() for Ruby 1.x
5
+ #
6
+ # Created: 17th February 2014
7
+ # Updated: 21st March 2019
8
+ #
9
+ # Author: Matthew Wilson
10
+ #
11
+ # Copyright (c) 2014-2019, Matthew Wilson and Synesis Software
12
+ # All rights reserved.
13
+ #
14
+ # Redistribution and use in source and binary forms, with or without
15
+ # modification, are permitted provided that the following conditions are met:
16
+ #
17
+ # * Redistributions of source code must retain the above copyright notice,
18
+ # this list of conditions and the following disclaimer.
19
+ #
20
+ # * Redistributions in binary form must reproduce the above copyright notice,
21
+ # this list of conditions and the following disclaimer in the documentation
22
+ # and/or other materials provided with the distribution.
23
+ #
24
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
+ # POSSIBILITY OF SUCH DAMAGE.
35
+ #
36
+ # ######################################################################### #
37
+
38
+
39
+ require 'recls/ximpl/util'
40
+
41
+ module Recls
42
+
43
+ # Combines paths
44
+ #
45
+ # === Signature
46
+ #
47
+ # * *Parameters:*
48
+ # - +paths+:: ([ (::String, ::Recls::Entry( ]) Array of 1 or more path
49
+ # elements to be combined
50
+ #
51
+ # === Return
52
+ # The combined path
53
+ def self.combine_paths(*paths)
54
+
55
+ paths = paths.reject { |p| p.nil? }
56
+ paths = paths.map { |p| 'Recls::Entry' == p.class.to_s ? p.path : p }
57
+
58
+ raise ArgumentError, 'must specify one or more path elements' if paths.empty?
59
+
60
+ return Recls::Ximpl.combine_paths paths, {}
61
+ end
62
+ end # module Recls
63
+
64
+ # ############################## end of file ############################# #
65
+
66
+
@@ -0,0 +1,77 @@
1
+ # ######################################################################### #
2
+ # File: recls/compare_paths_2plus.rb
3
+ #
4
+ # Purpose: Definition of Recls::compare_paths() for Ruby 2+
5
+ #
6
+ # Created: 17th February 2014
7
+ # Updated: 21st March 2019
8
+ #
9
+ # Author: Matthew Wilson
10
+ #
11
+ # Copyright (c) 2014-2019, Matthew Wilson and Synesis Software
12
+ # All rights reserved.
13
+ #
14
+ # Redistribution and use in source and binary forms, with or without
15
+ # modification, are permitted provided that the following conditions are met:
16
+ #
17
+ # * Redistributions of source code must retain the above copyright notice,
18
+ # this list of conditions and the following disclaimer.
19
+ #
20
+ # * Redistributions in binary form must reproduce the above copyright notice,
21
+ # this list of conditions and the following disclaimer in the documentation
22
+ # and/or other materials provided with the distribution.
23
+ #
24
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
+ # POSSIBILITY OF SUCH DAMAGE.
35
+ #
36
+ # ######################################################################### #
37
+
38
+
39
+ require 'recls/ximpl/util'
40
+
41
+ module Recls
42
+
43
+ # Combines paths, optionally canonicalising them
44
+ #
45
+ # === Signature
46
+ #
47
+ # * *Parameters:*
48
+ # - +paths+:: ([ (::String, ::Recls::Entry( ]) Array of 1 or more path
49
+ # elements to be combined
50
+ # - +options+:: (::Hash) Options that moderate the combination
51
+ #
52
+ # * *Options:*
53
+ # - +:canonicalise+:: (boolean) Causes the evaluated path to be
54
+ # canonicalised - with +Recls.canonicalise_path+ - before it is
55
+ # returned
56
+ # - +:clean+:: (boolean) Causes the evaluated path to be cleaned
57
+ # (i.e. sent to +cleanpath+) before it is returned. Ignored if
58
+ # +:canonicalise+ is specified
59
+ # - +:clean_path+:: (boolean) Equivalent to +:clean+, but deprecated
60
+ # and may be removed in a future version
61
+ #
62
+ # === Return
63
+ # The combined path
64
+ def self.combine_paths(*paths, **options)
65
+
66
+ paths = paths.reject { |p| p.nil? }
67
+ paths = paths.map { |p| 'Recls::Entry' == p.class.to_s ? p.path : p }
68
+
69
+ raise ArgumentError, 'must specify one or more path elements' if paths.empty?
70
+
71
+ return Recls::Ximpl.combine_paths paths, options
72
+ end
73
+ end # module Recls
74
+
75
+ # ############################## end of file ############################# #
76
+
77
+
data/lib/recls/entry.rb CHANGED
@@ -360,3 +360,4 @@ end
360
360
 
361
361
  # ############################## end of file ############################# #
362
362
 
363
+
@@ -4,11 +4,11 @@
4
4
  # Purpose: Defines the Recls::FileSearch class for the recls.Ruby library.
5
5
  #
6
6
  # Created: 24th July 2012
7
- # Updated: 13th June 2016
7
+ # Updated: 21st March 2019
8
8
  #
9
9
  # Author: Matthew Wilson
10
10
  #
11
- # Copyright (c) 2012-2015, Matthew Wilson and Synesis Software
11
+ # Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
12
12
  # All rights reserved.
13
13
  #
14
14
  # Redistribution and use in source and binary forms, with or without
@@ -46,6 +46,30 @@ module Recls
46
46
 
47
47
  include Enumerable
48
48
 
49
+ # Initialises a +FileSearch+ instance, which acts as an +Enumerable+
50
+ # of Recls::Entry
51
+ #
52
+ # === Signature
53
+ #
54
+ # * *Parameters:*
55
+ # - +search_root+:: (String, Recls::Entry) The root directory of
56
+ # the search. May be +nil+, in which case the current directory
57
+ # is assumed
58
+ # - +patterns+:: (String, Array) The pattern(s) for which to
59
+ # search. May be +nil+, in which case +Recls::WILDCARDS_ALL+ is
60
+ # assumed
61
+ # - +options+:: (Hash, Integer) Combination of flags (with
62
+ # behaviour as described below for the +flags+ option), or an
63
+ # options hash
64
+ #
65
+ # * *Options:*
66
+ # - +flags+:: (Integer) Combination of flags - FILES,
67
+ # DIRECTORIES, RECURSIVE, etc. If the value modulo TYPEMASK is 0,
68
+ # then FILES is assumed
69
+ #
70
+ # === Return
71
+ # An instance of the class
72
+ #
49
73
  def initialize(search_root, patterns, options={})
50
74
 
51
75
  # for backwards compatibility, we allow for options to
@@ -101,12 +125,12 @@ module Recls
101
125
  end
102
126
 
103
127
  # now de-dup the patterns, to avoid duplicates in search
104
- patterns = patterns.flatten
105
- patterns = patterns.uniq
128
+ patterns = patterns.flatten
129
+ patterns = patterns.uniq
106
130
 
107
131
  @search_root = search_root
108
- @patterns = patterns
109
- @flags = flags
132
+ @patterns = patterns
133
+ @flags = flags
110
134
  end
111
135
 
112
136
  attr_reader :search_root
@@ -291,3 +315,4 @@ end
291
315
 
292
316
  # ############################## end of file ############################# #
293
317
 
318
+
data/lib/recls/flags.rb CHANGED
@@ -75,3 +75,4 @@ end
75
75
 
76
76
  # ############################## end of file ############################# #
77
77
 
78
+
data/lib/recls/foreach.rb CHANGED
@@ -101,3 +101,4 @@ end
101
101
 
102
102
  # ############################## end of file ############################# #
103
103
 
104
+
data/lib/recls/recls.rb CHANGED
@@ -112,3 +112,4 @@ end
112
112
 
113
113
  # ############################## end of file ############################# #
114
114
 
115
+
data/lib/recls/stat.rb CHANGED
@@ -4,11 +4,11 @@
4
4
  # Purpose: Defines the Recls.stat() method for the recls.Ruby library.
5
5
  #
6
6
  # Created: 24th July 2012
7
- # Updated: 22nd June 2017
7
+ # Updated: 21st March 2019
8
8
  #
9
9
  # Author: Matthew Wilson
10
10
  #
11
- # Copyright (c) 2012-2017, Matthew Wilson and Synesis Software
11
+ # Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
12
12
  # All rights reserved.
13
13
  #
14
14
  # Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,34 @@ require 'recls/flags'
41
41
 
42
42
  module Recls
43
43
 
44
+ # Performs a +stat()+ but returns +nil+ if an obtained entry is not a
45
+ # directory
46
+ def self.directory?(path, *args)
47
+
48
+ fe = self.stat(path, *args)
49
+
50
+ if fe
51
+
52
+ return nil unless fe.directory?
53
+ end
54
+
55
+ fe
56
+ end
57
+
58
+ # Performs a +stat()+ but returns +nil+ if an obtained entry is not a
59
+ # file
60
+ def self.file?(path, *args)
61
+
62
+ fe = self.stat(path, *args)
63
+
64
+ if fe
65
+
66
+ return nil unless fe.file?
67
+ end
68
+
69
+ fe
70
+ end
71
+
44
72
  # USAGE:
45
73
  #
46
74
  # - stat(path)
@@ -100,8 +128,9 @@ module Recls
100
128
  nil
101
129
  end
102
130
  end
103
- end
131
+ end
104
132
  end
105
133
 
106
134
  # ############################## end of file ############################# #
107
135
 
136
+
data/lib/recls/util.rb CHANGED
@@ -4,11 +4,11 @@
4
4
  # Purpose: Utility module functions for recls library
5
5
  #
6
6
  # Created: 17th February 2014
7
- # Updated: 25th January 2018
7
+ # Updated: 21st March 2019
8
8
  #
9
9
  # Author: Matthew Wilson
10
10
  #
11
- # Copyright (c) 2012-2018, Matthew Wilson and Synesis Software
11
+ # Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
12
12
  # All rights reserved.
13
13
  #
14
14
  # Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,8 @@ module Recls
44
44
  # Obtains the absolute form of the given path
45
45
  def self.absolute_path(path)
46
46
 
47
+ return path.path if 'Recls::Entry' === path.class.to_s
48
+
47
49
  return Recls::Ximpl.absolute_path path
48
50
  end
49
51
 
@@ -51,6 +53,8 @@ module Recls
51
53
  # directories
52
54
  def self.canonicalise_path(path)
53
55
 
56
+ path = path.path if 'Recls::Entry' === path.class.to_s
57
+
54
58
  return Recls::Ximpl.canonicalise_path path
55
59
  end
56
60
 
@@ -60,36 +64,14 @@ module Recls
60
64
 
61
65
  return Recls::Ximpl.derive_relative_path origin, path
62
66
  end
67
+ end # module Recls
63
68
 
64
- # Combines paths, optionally canonicalising them
65
- #
66
- # === Signature
67
- #
68
- # * *Parameters:*
69
- # - +paths+:: [ [ ::String, ::Recls::Entry ] ] Array of 1 or more path
70
- # elements to be combined
71
- # - +options+:: [::Hash] Options that moderate the combination
72
- #
73
- # * *Parameters:*
74
- # - +:canonicalise+:: [boolean] Causes the evaluated path to be
75
- # canonicalised - with +Recls.canonicalise_path+ - before it is
76
- # returned
77
- # - +:clean+:: [boolean] Causes the evaluated path to be cleaned
78
- # (i.e. sent to +cleanpath+) before it is returned. Ignored if
79
- # +:canonicalise+ is specified
80
- # - +:clean_path+:: [boolean] Equivalent to +:clean+, but deprecated
81
- # and may be removed in a future version
82
- #
83
- # === Return
84
- # The combined path
85
- def self.combine_paths(*paths, **options)
86
-
87
- paths = paths.reject { |p| p.nil? }
88
-
89
- raise ArgumentError, 'must specify one or more path elements' if paths.empty?
90
-
91
- return Recls::Ximpl.combine_paths paths, options
92
- end
69
+ if RUBY_VERSION >= '2'
70
+
71
+ require 'recls/combine_paths_2plus'
72
+ else
73
+
74
+ require 'recls/combine_paths_1'
93
75
  end
94
76
 
95
77
  # ############################## end of file ############################# #
data/lib/recls/version.rb CHANGED
@@ -4,11 +4,11 @@
4
4
  # Purpose: Version for recls library
5
5
  #
6
6
  # Created: 14th February 2014
7
- # Updated: 5th February 2018
7
+ # Updated: 21st March 2019
8
8
  #
9
9
  # Author: Matthew Wilson
10
10
  #
11
- # Copyright (c) 2012-2018, Matthew Wilson and Synesis Software
11
+ # Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
12
12
  # All rights reserved.
13
13
  #
14
14
  # Redistribution and use in source and binary forms, with or without
@@ -39,7 +39,7 @@
39
39
  module Recls
40
40
 
41
41
  # Current version of the recls.Ruby library
42
- VERSION = '2.8.2'
42
+ VERSION = '2.9.0'
43
43
 
44
44
  private
45
45
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -4,11 +4,11 @@
4
4
  # Purpose: Internal implementation constructs for the recls library.
5
5
  #
6
6
  # Created: 24th July 2012
7
- # Updated: 25th January 2018
7
+ # Updated: 21st Jannuary 2019
8
8
  #
9
9
  # Author: Matthew Wilson
10
10
  #
11
- # Copyright (c) 2012-2018, Matthew Wilson and Synesis Software
11
+ # Copyright (c) 2012-2019, Matthew Wilson and Synesis Software
12
12
  # All rights reserved.
13
13
  #
14
14
  # Redistribution and use in source and binary forms, with or without
@@ -459,13 +459,14 @@ module Recls
459
459
 
460
460
  case path
461
461
  when ::NilClass
462
+
462
463
  return nil
463
464
  when ::String
464
- when ::Recls::Entry
465
+
465
466
  path = path.to_s
466
467
  else
467
468
 
468
- raise TypeError, "parameter path ('#{path}') is of type #{path.class} must be an instance of #{::String} or #{::Recls::Entry}"
469
+ raise TypeError, "parameter path ('#{path}') is of type #{path.class} must be an instance of #{::String} or Recls::Entry"
469
470
  end
470
471
 
471
472
  return '' if path.empty?
@@ -721,7 +722,7 @@ module Recls
721
722
 
722
723
  paths = paths[abs_ix..-1]
723
724
 
724
- r = File.join *paths
725
+ r = File.join(*paths)
725
726
 
726
727
  cap = options[:canonicalise] || options[:canonicalize]
727
728
 
@@ -1,6 +1,6 @@
1
1
  #! /usr/bin/ruby
2
2
  #
3
- # test Recls entry methods
3
+ # test Recls entry methods showing parts
4
4
 
5
5
  $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
6
6
 
@@ -19,11 +19,11 @@ Recls::FileSearch.new(root_dir, patterns, Recls::FILES | Recls::RECURSIVE).each
19
19
  puts fe.short_path
20
20
  puts fe.directory_path
21
21
  puts drive
22
- puts "".ljust(drive ? drive.size : 0) + fe.directory
23
- puts "".ljust(fe.directory_path.size) + fe.file
24
- puts "".ljust(fe.directory_path.size) + "#{fe.file_short_name}"
25
- puts "".ljust(fe.directory_path.size) + fe.stem
26
- puts "".ljust(fe.directory_path.size + fe.stem.size) + fe.extension
22
+ puts "".ljust(drive ? drive.size : 0) + fe.directory.to_s
23
+ puts "".ljust(fe.directory_path.size) + fe.file.to_s
24
+ puts "".ljust(fe.directory_path.size) + fe.file_short_name.to_s
25
+ puts "".ljust(fe.directory_path.size) + fe.stem.to_s
26
+ puts "".ljust(fe.directory_path.size + fe.stem.size) + fe.extension.to_s
27
27
  n = drive.size
28
28
  fe.directory_parts.each do |part|
29
29
 
@@ -32,9 +32,9 @@ Recls::FileSearch.new(root_dir, patterns, Recls::FILES | Recls::RECURSIVE).each
32
32
  end
33
33
 
34
34
  puts fe.search_directory
35
- puts "".ljust(fe.search_directory.size) + fe.search_relative_path
36
- puts "".ljust(fe.search_directory.size) + fe.search_relative_directory_path
37
- puts "".ljust(fe.search_directory.size) + fe.search_relative_directory
35
+ puts "".ljust(fe.search_directory.size) + fe.search_relative_path.to_s
36
+ puts "".ljust(fe.search_directory.size) + fe.search_relative_directory_path.to_s
37
+ puts "".ljust(fe.search_directory.size) + fe.search_relative_directory.to_s
38
38
 
39
39
  n = fe.search_directory.size
40
40
  fe.search_relative_directory_parts.each do |part|
@@ -15,6 +15,7 @@ def show_entry f
15
15
  puts "entry:"
16
16
  puts "\t#{'(entry)'.ljust(20)}\t#{f}"
17
17
  puts "\t#{'f.path'.ljust(20)}\t#{f.path}"
18
+ puts "\t#{'f.compare_path'.ljust(20)}\t#{f.compare_path}"
18
19
  puts "\t#{'f.drive'.ljust(20)}\t#{f.drive}"
19
20
  puts "\t#{'f.directory_path'.ljust(20)}\t#{f.directory_path}"
20
21
  puts "\t#{'f.directory'.ljust(20)}\t#{f.directory}"
@@ -23,11 +24,6 @@ puts "\t#{'f.directory_parts'.ljust(20)}\t[#{directory_parts.size}]"
23
24
  directory_parts.each do |part|
24
25
  puts "\t#{''.ljust(20)}\t\t#{part}"
25
26
  end
26
- search_relative_directory_parts = f.search_relative_directory_parts
27
- puts "\t#{'f.search_relative_directory_parts'.ljust(20)}\t[#{search_relative_directory_parts.size}]"
28
- search_relative_directory_parts.each do |part|
29
- puts "\t#{''.ljust(20)}\t\t#{part}"
30
- end
31
27
  puts "\t#{'f.file_full_name'.ljust(20)}\t#{f.file_full_name}"
32
28
  puts "\t#{'f.file_short_name'.ljust(20)}\t#{f.file_short_name}"
33
29
  puts "\t#{'f.file_name_only'.ljust(20)}\t#{f.file_name_only}"
@@ -37,6 +33,11 @@ puts "\t#{'f.search_directory'.ljust(20)}\t#{f.search_directory}"
37
33
  puts "\t#{'f.search_relative_path'.ljust(20)}\t#{f.search_relative_path}"
38
34
  puts "\t#{'f.search_relative_directory'.ljust(20)}\t#{f.search_relative_directory}"
39
35
  puts "\t#{'f.search_relative_directory_path'.ljust(20)}\t#{f.search_relative_directory_path}"
36
+ search_relative_directory_parts = f.search_relative_directory_parts
37
+ puts "\t#{'f.search_relative_directory_parts'.ljust(20)}\t[#{search_relative_directory_parts.size}]"
38
+ search_relative_directory_parts.each do |part|
39
+ puts "\t#{''.ljust(20)}\t\t#{part}"
40
+ end
40
41
 
41
42
  puts "\t#{'f.size'.ljust(20)}\t#{f.size}"
42
43
 
@@ -52,12 +53,12 @@ puts "\t#{'f.last_access_time'.ljust(20)}\t#{f.last_access_time}"
52
53
  end
53
54
 
54
55
  puts
55
- puts "stat of '.':"
56
- show_entry Recls::stat '.'
56
+ puts "stat of '.' (from '.'):"
57
+ show_entry Recls::stat '.', '.'
57
58
 
58
59
  puts
59
- puts "stat of '~':"
60
- show_entry Recls::stat '~'
60
+ puts "stat of '~' (from '.'):"
61
+ show_entry Recls::stat '~', '.'
61
62
 
62
63
  puts
63
64
  puts "directories:"
@@ -1,23 +1,15 @@
1
- #!/usr/bin/ruby
2
-
3
- #############################################################################
4
- # File: ./test/scratch/test_files_and_directories.rb
5
- #
6
- # Purpose: COMPLETE_ME
7
- #
8
- # Created: 09 06 2016
9
- # Updated: 09 06 2016
1
+ #! /usr/bin/ruby
10
2
  #
11
- # Author: Matthew Wilson
12
- #
13
- # Copyright: <<TBD>>
14
- #
15
- #############################################################################
3
+ # test Search between files and directories
16
4
 
17
5
  $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
18
6
 
19
7
  require 'recls'
20
8
 
9
+ puts
10
+ puts "adding own trailing slash:"
11
+ puts
12
+
21
13
  Recls::FileSearch.new(nil, nil, Recls::FILES | Recls::DIRECTORIES | Recls::RECURSIVE).each do |fe|
22
14
 
23
15
  path = fe.search_relative_path
@@ -31,3 +23,14 @@ Recls::FileSearch.new(nil, nil, Recls::FILES | Recls::DIRECTORIES | Recls::RECUR
31
23
  end
32
24
  end
33
25
 
26
+ puts
27
+ puts "specifying flag for trailing slash:"
28
+ puts
29
+
30
+ Recls::FileSearch.new(nil, nil, Recls::FILES | Recls::DIRECTORIES | Recls::RECURSIVE | Recls::MARK_DIRECTORIES).each do |fe|
31
+
32
+ path = fe.search_relative_path
33
+
34
+ puts path
35
+ end
36
+
@@ -4,10 +4,7 @@
4
4
 
5
5
  $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
6
6
 
7
-
8
- #require 'recls/util'
9
7
  require 'recls/foreach'
10
- #require 'recls'
11
8
 
12
9
  puts
13
10
  puts "with given block:"
@@ -1,6 +1,6 @@
1
- #!/usr/bin/ruby
1
+ #! /usr/bin/ruby
2
2
  #
3
- # test Recls entry methods
3
+ # test Recls entry methods showing parts, via module function
4
4
 
5
5
  $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
6
6
 
@@ -19,11 +19,11 @@ Recls.FileSearch(root_dir, patterns, flags: Recls::FILES).each do |fe|
19
19
  puts fe.short_path
20
20
  puts fe.directory_path
21
21
  puts drive
22
- puts "".ljust(drive ? drive.size : 0) + fe.directory
23
- puts "".ljust(fe.directory_path.size) + fe.file
24
- puts "".ljust(fe.directory_path.size) + "#{fe.file_short_name}"
25
- puts "".ljust(fe.directory_path.size) + fe.stem
26
- puts "".ljust(fe.directory_path.size + fe.stem.size) + fe.extension
22
+ puts "".ljust(drive ? drive.size : 0) + fe.directory.to_s
23
+ puts "".ljust(fe.directory_path.size) + fe.file.to_s
24
+ puts "".ljust(fe.directory_path.size) + fe.file_short_name.to_s
25
+ puts "".ljust(fe.directory_path.size) + fe.stem.to_s
26
+ puts "".ljust(fe.directory_path.size + fe.stem.size) + fe.extension.to_s
27
27
  n = drive.size
28
28
  fe.directory_parts.each do |part|
29
29
 
@@ -32,9 +32,9 @@ Recls.FileSearch(root_dir, patterns, flags: Recls::FILES).each do |fe|
32
32
  end
33
33
 
34
34
  puts fe.search_directory
35
- puts "".ljust(fe.search_directory.size) + fe.search_relative_path
36
- puts "".ljust(fe.search_directory.size) + fe.search_relative_directory_path
37
- puts "".ljust(fe.search_directory.size) + fe.search_relative_directory
35
+ puts "".ljust(fe.search_directory.size) + fe.search_relative_path.to_s
36
+ puts "".ljust(fe.search_directory.size) + fe.search_relative_directory_path.to_s
37
+ puts "".ljust(fe.search_directory.size) + fe.search_relative_directory.to_s
38
38
 
39
39
  n = fe.search_directory.size
40
40
  fe.search_relative_directory_parts.each do |part|
@@ -1,4 +1,4 @@
1
- #!/usr/bin/ruby
1
+ #! /usr/bin/ruby
2
2
  #
3
3
  # Demonstrates use of dev and ino attributes
4
4
 
@@ -8,14 +8,14 @@ require 'recls'
8
8
 
9
9
  puts
10
10
  puts "Hidden directories:"
11
- Recls::FileSearch.new(nil, nil, Recls::RECURSIVE | Recls::DIRECTORIES | Recls::SHOW_HIDDEN).each do |fe|
11
+ Recls.file_rsearch(nil, nil, Recls::DIRECTORIES | Recls::SHOW_HIDDEN).each do |fe|
12
12
 
13
13
  puts "\t#{fe.search_relative_path}" if fe.hidden?
14
14
  end
15
15
 
16
16
  puts
17
17
  puts "Hidden files:"
18
- Recls::FileSearch.new(nil, nil, Recls::RECURSIVE | Recls::FILES | Recls::SHOW_HIDDEN).each do |fe|
18
+ Recls.file_search(nil, nil, Recls::RECURSIVE | Recls::FILES | Recls::SHOW_HIDDEN).each do |fe|
19
19
 
20
20
  puts "\t#{fe.search_relative_path}" if fe.hidden?
21
21
  end
@@ -23,7 +23,7 @@ end
23
23
 
24
24
  puts
25
25
  puts "Hidden directories & files:"
26
- Recls::FileSearch.new(nil, nil, Recls::RECURSIVE | Recls::DIRECTORIES | Recls::FILES | Recls::MARK_DIRECTORIES | Recls::SHOW_HIDDEN).each do |fe|
26
+ Recls.file_search(nil, nil, Recls::RECURSIVE | Recls::DIRECTORIES | Recls::FILES | Recls::MARK_DIRECTORIES | Recls::SHOW_HIDDEN).each do |fe|
27
27
 
28
28
  puts "\t#{fe.search_relative_path}" if fe.hidden?
29
29
  end
@@ -56,6 +56,7 @@ class Test_combine_paths < Test::Unit::TestCase
56
56
  assert_equal 'abc/def/ghi', Recls.combine_paths('abc/', 'def/ghi')
57
57
  assert_equal 'abc/./def/ghi', Recls.combine_paths('abc/.', 'def/ghi')
58
58
  assert_equal 'abc/./def/ghi', Recls.combine_paths('abc/./', 'def/ghi')
59
+ if RUBY_VERSION >= '2'
59
60
  assert_equal 'abc/./def/ghi', Recls.combine_paths('abc/.', 'def/ghi', clean_path: false)
60
61
  assert_equal 'abc/./def/ghi', Recls.combine_paths('abc/./', 'def/ghi', clean: false)
61
62
  assert_equal 'abc/def/ghi', Recls.combine_paths('abc/.', 'def/ghi', clean_path: true)
@@ -63,16 +64,19 @@ class Test_combine_paths < Test::Unit::TestCase
63
64
  assert_equal 'abc/def/ghi', Recls.combine_paths('abc/./.', 'def/ghi', clean_path: true)
64
65
  assert_equal 'abc/../def/ghi', Recls.combine_paths('abc/..', 'def/ghi')
65
66
  assert_equal 'def/ghi', Recls.combine_paths('abc/..', 'def/ghi', clean_path: true)
67
+ end
66
68
  end
67
69
 
68
70
  def test_multiple_relative
69
71
 
72
+ if RUBY_VERSION >= '2'
70
73
  assert_equal 'a/b/c/d/e/f/g', Recls.combine_paths('a', 'b', 'c', 'd/e/f/', 'g', clean: false)
71
74
  assert_equal 'a/b/c/d/e/f/g', Recls.combine_paths('a', 'b', 'c', 'd/e/f/', 'g', clean: true)
72
75
 
73
76
  assert_equal 'a/b/c/../d/e/f/g', Recls.combine_paths('a', 'b', 'c', '..', 'd/e/f/', 'g', clean: false)
74
77
  assert_equal 'a/b/d/e/f/g', Recls.combine_paths('a', 'b', 'c', '..', 'd/e/f/', 'g/', clean: true)
75
78
  assert_equal 'a/b/d/e/f/g/', Recls.combine_paths('a', 'b', 'c', '..', 'd/e/f/', 'g/', canonicalise: true)
79
+ end
76
80
  end
77
81
 
78
82
  def test_various_absolute_placings
@@ -87,8 +91,10 @@ class Test_combine_paths < Test::Unit::TestCase
87
91
 
88
92
  assert_equal '/f/g', Recls.combine_paths('/', 'a', 'b', 'c', 'd/e', '/f/g')
89
93
  assert_equal '/f/g/', Recls.combine_paths('/', 'a', 'b', 'c', 'd/e', '/f/g/')
94
+ if RUBY_VERSION >= '2'
90
95
  assert_equal '/f/g', Recls.combine_paths('/', 'a', 'b', 'c', 'd/e', '/f/g/', clean: true)
91
96
  assert_equal '/f/g/', Recls.combine_paths('/', 'a', 'b', 'c', 'd/e', '/f/g/', canonicalise: true)
97
+ end
92
98
  end
93
99
  end
94
100
 
@@ -708,6 +708,53 @@ class Test_Recls_Ximpl_derive_relative_path < Test::Unit::TestCase
708
708
 
709
709
  end
710
710
 
711
+ M = Recls::Ximpl
712
+
713
+ def test_libpath_cases_test_nils_and_empties
714
+
715
+ # to get nowhere from nowhere, go nowhere
716
+ assert_nil M.derive_relative_path(nil, nil)
717
+ assert_nil M.derive_relative_path('', nil)
718
+ assert_nil M.derive_relative_path('', '')
719
+ assert_nil M.derive_relative_path(nil, '')
720
+
721
+ # to get somewhere from nowhere, just go there
722
+ assert_equal 'abc', M.derive_relative_path(nil, 'abc')
723
+ assert_equal 'abc', M.derive_relative_path('', 'abc')
724
+
725
+ # to get nowhere from anywhere else, go nowhere
726
+ assert_nil M.derive_relative_path('dir', nil)
727
+ assert_nil M.derive_relative_path('dir', '')
728
+ end
729
+
730
+ def test_libpath_cases_test_same_location
731
+
732
+ assert_equal '.', M.derive_relative_path('abc', 'abc')
733
+ assert_equal './', M.derive_relative_path('abc/', 'abc/')
734
+ assert_equal './', M.derive_relative_path('abc', 'abc/')
735
+
736
+ assert_equal './', M.derive_relative_path('/', '/')
737
+
738
+ =begin
739
+
740
+ assert_equal '.', M.derive_relative_path('./abc', 'abc')
741
+ =end
742
+ assert_equal '.', M.derive_relative_path('./abc/', 'abc')
743
+ =begin
744
+
745
+ assert_equal './', M.derive_relative_path('./abc', 'abc/')
746
+ =end
747
+ assert_equal './', M.derive_relative_path('./abc/', 'abc/')
748
+ end
749
+
750
+ def test_libpath_cases_test_one_above
751
+
752
+ =begin
753
+
754
+ assert_equal '..', M.derive_relative_path('.', '..')
755
+ =end
756
+ end
757
+
711
758
  def test_absolute_proper_subset
712
759
 
713
760
  assert_equal('abc', Recls::Ximpl::derive_relative_path('/dir1/dir2', '/dir1/dir2/abc'))
@@ -720,9 +767,11 @@ class Test_Recls_Ximpl_derive_relative_path < Test::Unit::TestCase
720
767
  assert_equal('abc/', Recls::Ximpl::derive_relative_path('dir1/dir2', 'dir1/dir2/abc/'))
721
768
  assert_equal('abc/', Recls::Ximpl::derive_relative_path('dir1/dir2/', 'dir1/dir2/abc/'))
722
769
 
723
- # assert_equal('/dir/dir2/abc', Recls::Ximpl::derive_relative_path('/dir1/dir2/abc', 'dir1/dir2'))
724
- # assert_equal('/dir/dir2/abc', Recls::Ximpl::derive_relative_path('/dir1/dir2/abc', 'dir1/dir2/'))
770
+ =begin
725
771
 
772
+ assert_equal('/dir/dir2/abc', Recls::Ximpl::derive_relative_path('/dir1/dir2/abc', 'dir1/dir2'))
773
+ assert_equal('/dir/dir2/abc', Recls::Ximpl::derive_relative_path('/dir1/dir2/abc', 'dir1/dir2/'))
774
+ =end
726
775
  end
727
776
 
728
777
  def test_absolute_proper_subset_2
data/test/unit/ts_all.rb CHANGED
@@ -2,19 +2,21 @@
2
2
  #
3
3
  # executes all other tests
4
4
 
5
- this_file = File.expand_path(__FILE__)
6
- this_dir = File.expand_path(File.dirname(__FILE__))
7
- $:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
5
+ this_dir = File.expand_path(File.dirname(__FILE__))
8
6
 
9
- puts "executing all test cases in directory #{this_dir}"
7
+ # all tc_*rb in current directory
8
+ Dir[File.join(this_dir, 'tc_*rb')].each do |file|
10
9
 
11
- Dir["#{this_dir}/*.rb"].each do |file|
12
-
13
- next if this_file == file
10
+ $stderr.puts "requiring file '#{file}'" if $DEBUG
14
11
 
15
12
  require file
16
-
17
13
  end
18
14
 
19
- require 'test/unit'
15
+ # all ts_*rb in immediate sub-directories
16
+ Dir[File.join(this_dir, '*', 'ts_*rb')].each do |file|
17
+
18
+ $stderr.puts "requiring file '#{file}'" if $DEBUG
19
+
20
+ require file
21
+ end
20
22
 
metadata CHANGED
@@ -1,18 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recls-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.2
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-05 00:00:00.000000000 Z
11
+ date: 2019-03-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: |
14
- RECursive LS for Ruby
15
- email: matthew@recls.org
13
+ description: 'RECursive LS for Ruby
14
+
15
+ '
16
+ email: matthew@synesis.com.au
16
17
  executables: []
17
18
  extensions: []
18
19
  extra_rdoc_files: []
@@ -24,6 +25,8 @@ files:
24
25
  - examples/show_readonly_files.rb
25
26
  - lib/recls.rb
26
27
  - lib/recls/api.rb
28
+ - lib/recls/combine_paths_1.rb
29
+ - lib/recls/combine_paths_2plus.rb
27
30
  - lib/recls/entry.rb
28
31
  - lib/recls/file_search.rb
29
32
  - lib/recls/flags.rb
@@ -54,7 +57,7 @@ files:
54
57
  - test/unit/ts_all.rb
55
58
  homepage: http://recls.org/
56
59
  licenses:
57
- - 3-clause BSD
60
+ - BSD-3-Clause
58
61
  metadata: {}
59
62
  post_install_message:
60
63
  rdoc_options: []
@@ -62,19 +65,18 @@ require_paths:
62
65
  - lib
63
66
  required_ruby_version: !ruby/object:Gem::Requirement
64
67
  requirements:
65
- - - '>='
68
+ - - ">="
66
69
  - !ruby/object:Gem::Version
67
- version: '0'
70
+ version: 1.9.3
68
71
  required_rubygems_version: !ruby/object:Gem::Requirement
69
72
  requirements:
70
- - - '>='
73
+ - - ">="
71
74
  - !ruby/object:Gem::Version
72
75
  version: '0'
73
76
  requirements: []
74
77
  rubyforge_project:
75
- rubygems_version: 2.4.2
78
+ rubygems_version: 2.6.11
76
79
  signing_key:
77
80
  specification_version: 4
78
81
  summary: recls.Ruby
79
82
  test_files: []
80
- has_rdoc: