Class: Recls::FileSearch
- Includes:
- Enumerable
- Defined in:
- lib/recls/obsolete.rb,
lib/recls/file_search.rb
Overview
:nodoc: all
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
(Integer) The search flags.
-
#patterns ⇒ Object
(also: #pattern)
readonly
(String) The search patterns.
-
#search_root ⇒ Object
(also: #searchRoot)
readonly
(String) The search root.
Instance Method Summary collapse
-
#initialize(search_root, patterns, options = {}) ⇒ FileSearch
constructor
Initialises a
FileSearch
instance, which acts as anEnumerable
of Recls::Entry.
Constructor Details
#initialize(search_root, patterns, options = {}) ⇒ FileSearch
Initialises a FileSearch
instance, which acts as an Enumerable
of Recls::Entry
Signature
-
Parameters:
-
search_root
(String, Recls::Entry) The root directory of the search. May benil
, in which case the current directory is assumed -
patterns
(String, Array) The pattern(s) for which to search. May benil
, in which caseRecls::WILDCARDS_ALL
is assumed -
options
(Hash, Integer) Combination of flags (with behaviour as described below for theflags
option), or an options hash
-
-
Options:
-
flags
(Integer) Combination of flags - FILES, DIRECTORIES, RECURSIVE, etc. If the value modulo TYPEMASK is 0, then FILES is assumed
-
Return
An instance of the class
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 |
# File 'lib/recls/file_search.rb', line 70 def initialize(search_root, patterns, ={}) # for backwards compatibility, we allow for options to # be a number flags = 0 case when ::NilClass = { flags: 0 } when ::Integer flags = = { flags: flags } when ::Hash flags = [:flags] || 0 else raise ArgumentError, "options parameter must a #{::Hash}, nil, or an integer specifying flags - an instance of #{.class} given" end if not search_root search_root = '.' else search_root = search_root.to_s end search_root = '.' if search_root.empty? search_root = File.(search_root) if '~' == search_root[0] case patterns when NilClass patterns = [] when String patterns = patterns.split(/[|#{Recls::Ximpl::OS::PATH_SEPARATOR}]/) when Array else patterns = patterns.to_a end patterns = [ Recls::WILDCARDS_ALL ] if patterns.empty? if(0 == (Recls::TYPEMASK & flags)) flags |= Recls::FILES end # now de-dup the patterns, to avoid duplicates in search patterns = patterns.flatten patterns = patterns.uniq @search_root = search_root @patterns = patterns @flags = flags end |
Instance Attribute Details
#flags ⇒ Object (readonly)
(Integer) The search flags
138 139 140 |
# File 'lib/recls/file_search.rb', line 138 def flags @flags end |
#patterns ⇒ Object (readonly) Also known as: pattern
(String) The search patterns
136 137 138 |
# File 'lib/recls/file_search.rb', line 136 def patterns @patterns end |
#search_root ⇒ Object (readonly) Also known as: searchRoot
(String) The search root
134 135 136 |
# File 'lib/recls/file_search.rb', line 134 def search_root @search_root end |