fakefs 2.1.0 → 2.3.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 +4 -4
- data/lib/fakefs/dir.rb +20 -7
- data/lib/fakefs/file_system.rb +24 -3
- data/lib/fakefs/fileutils.rb +2 -2
- data/lib/fakefs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b40516abdee28793eb6152f979b453e79ed3dfd42c205e65f500efca0bded1f
|
4
|
+
data.tar.gz: 249b21fc04c49b15cf5f81e5a1497bdb957749d78261337490308f2fa1bb756a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54376515f03734c2058dcc29733830dae79882dc235042a15bf2bfde1d6256f0eb373c85ae2408118c3f32bec00730cb7a2304225149c97a2d3a44cfe8b0a2ee
|
7
|
+
data.tar.gz: 2e15d1c5e506602d955bbcadc7b890946f133949a65e20327dd5bac5995fa6e69fc296750fd2dd3fe1e5b219e04f69a8f8f2cf9a528f63fe8971192e7c614aa8
|
data/lib/fakefs/dir.rb
CHANGED
@@ -37,6 +37,10 @@ module FakeFS
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def children
|
41
|
+
each.to_a
|
42
|
+
end
|
43
|
+
|
40
44
|
def pos
|
41
45
|
@pointer
|
42
46
|
end
|
@@ -96,9 +100,11 @@ module FakeFS
|
|
96
100
|
end
|
97
101
|
|
98
102
|
def self.each_child(dirname, &_block)
|
99
|
-
Dir.open(dirname) do |
|
100
|
-
|
101
|
-
|
103
|
+
Dir.open(dirname) do |dir|
|
104
|
+
dir.each do |file|
|
105
|
+
next if ['.', '..'].include?(file)
|
106
|
+
yield file
|
107
|
+
end
|
102
108
|
end
|
103
109
|
end
|
104
110
|
|
@@ -114,13 +120,17 @@ module FakeFS
|
|
114
120
|
end
|
115
121
|
|
116
122
|
def self.foreach(dirname, &_block)
|
117
|
-
Dir.open(dirname)
|
123
|
+
Dir.open(dirname) do |dir|
|
124
|
+
dir.each do |file|
|
125
|
+
yield file
|
126
|
+
end
|
127
|
+
end
|
118
128
|
end
|
119
129
|
|
120
130
|
def self.glob(pattern, _flags = 0, flags: _flags, base: nil, &block) # rubocop:disable Lint/UnderscorePrefixedVariableName
|
121
131
|
pwd = FileSystem.normalize_path(base || Dir.pwd)
|
122
132
|
matches_for_pattern = lambda do |matcher|
|
123
|
-
[FileSystem.
|
133
|
+
[FileSystem.find_with_glob(matcher, flags, true, dir: pwd) || []].flatten.map do |e|
|
124
134
|
pwd_regex = %r{\A#{pwd.gsub('+') { '\+' }}/?}
|
125
135
|
if pwd.match(%r{\A/?\z}) ||
|
126
136
|
!e.to_s.match(pwd_regex)
|
@@ -152,10 +162,13 @@ module FakeFS
|
|
152
162
|
end
|
153
163
|
|
154
164
|
def self.open(string, &_block)
|
165
|
+
dir = Dir.new(string)
|
155
166
|
if block_given?
|
156
|
-
|
167
|
+
result = yield(dir)
|
168
|
+
dir.close
|
169
|
+
result
|
157
170
|
else
|
158
|
-
|
171
|
+
dir
|
159
172
|
end
|
160
173
|
end
|
161
174
|
|
data/lib/fakefs/file_system.rb
CHANGED
@@ -20,13 +20,22 @@ module FakeFS
|
|
20
20
|
fs.entries
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
# Finds files/directories using the exact path, without expanding globs.
|
24
|
+
def find(path, dir: nil)
|
25
|
+
parts = path_parts(normalize_path(path, dir: dir))
|
26
|
+
return fs if parts.empty? # '/'
|
27
|
+
|
28
|
+
find_recurser(fs, parts)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Finds files/directories expanding globs.
|
32
|
+
def find_with_glob(path, find_flags = 0, gave_char_class = false, dir: nil)
|
24
33
|
parts = path_parts(normalize_path(path, dir: dir))
|
25
34
|
return fs if parts.empty? # '/'
|
26
35
|
|
27
36
|
entries = Globber.expand(path).flat_map do |pattern|
|
28
37
|
parts = path_parts(normalize_path(pattern, dir: dir))
|
29
|
-
|
38
|
+
find_with_glob_recurser(fs, parts, find_flags, gave_char_class).flatten
|
30
39
|
end
|
31
40
|
|
32
41
|
case entries.length
|
@@ -120,6 +129,18 @@ module FakeFS
|
|
120
129
|
private
|
121
130
|
|
122
131
|
def find_recurser(dir, parts, find_flags = 0, gave_char_class = false)
|
132
|
+
return nil unless dir.respond_to? :[]
|
133
|
+
head, *parts = parts
|
134
|
+
match = dir.entries.find { |e| e.name == head }
|
135
|
+
|
136
|
+
if parts.empty? # we're done recursing
|
137
|
+
match
|
138
|
+
else
|
139
|
+
find_recurser(match, parts, find_flags, gave_char_class)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def find_with_glob_recurser(dir, parts, find_flags = 0, gave_char_class = false)
|
123
144
|
return [] unless dir.respond_to? :[]
|
124
145
|
pattern, *parts = parts
|
125
146
|
matches =
|
@@ -149,7 +170,7 @@ module FakeFS
|
|
149
170
|
if parts.empty? # we're done recursing
|
150
171
|
matches
|
151
172
|
else
|
152
|
-
matches.map { |entry|
|
173
|
+
matches.map { |entry| find_with_glob_recurser(entry, parts, find_flags, gave_char_class) }
|
153
174
|
end
|
154
175
|
end
|
155
176
|
|
data/lib/fakefs/fileutils.rb
CHANGED
@@ -232,7 +232,7 @@ module FakeFS
|
|
232
232
|
list = Array(list)
|
233
233
|
list.each do |file|
|
234
234
|
chown(user, group, file)
|
235
|
-
[FileSystem.
|
235
|
+
[FileSystem.find_with_glob("#{file}/**/**")].flatten.each do |f|
|
236
236
|
chown(user, group, f.to_s)
|
237
237
|
end
|
238
238
|
end
|
@@ -255,7 +255,7 @@ module FakeFS
|
|
255
255
|
list = Array(list)
|
256
256
|
list.each do |file|
|
257
257
|
chmod(mode, file)
|
258
|
-
[FileSystem.
|
258
|
+
[FileSystem.find_with_glob("#{file}/**/**")].flatten.each do |f|
|
259
259
|
chmod(mode, f.to_s)
|
260
260
|
end
|
261
261
|
end
|
data/lib/fakefs/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakefs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2023-02-
|
15
|
+
date: 2023-02-12 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bump
|