memfs 0.5.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.hound.yml +2 -0
- data/.rspec +1 -1
- data/.rubocop.yml +1 -0
- data/.ruby-style.yml +335 -0
- data/.travis.yml +6 -3
- data/CHANGELOG.md +12 -1
- data/README.md +6 -5
- data/lib/memfs.rb +29 -2
- data/lib/memfs/dir.rb +6 -6
- data/lib/memfs/fake/directory.rb +5 -2
- data/lib/memfs/fake/file.rb +4 -5
- data/lib/memfs/fake/file/content.rb +0 -2
- data/lib/memfs/file.rb +27 -20
- data/lib/memfs/file/stat.rb +1 -1
- data/lib/memfs/file_system.rb +3 -3
- data/lib/memfs/io.rb +190 -154
- data/lib/memfs/version.rb +1 -1
- data/memfs.gemspec +4 -1
- data/spec/fileutils_spec.rb +23 -18
- data/spec/memfs/dir_spec.rb +20 -9
- data/spec/memfs/fake/directory_spec.rb +5 -1
- data/spec/memfs/fake/entry_spec.rb +5 -5
- data/spec/memfs/fake/file/content_spec.rb +1 -1
- data/spec/memfs/fake/file_spec.rb +1 -1
- data/spec/memfs/fake/symlink_spec.rb +2 -2
- data/spec/memfs/file/stat_spec.rb +6 -3
- data/spec/memfs/file_spec.rb +140 -57
- data/spec/memfs/file_system_spec.rb +5 -4
- data/spec/memfs_spec.rb +39 -2
- data/spec/spec_helper.rb +23 -21
- metadata +22 -6
- data/.rubocop.yml +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fb81cdc4d216ab47c2b1ffde22a27e9004e0fa2
|
4
|
+
data.tar.gz: 6736cda24f5ac40ed805dc60e1ee277e34b7014f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b0832e3983bb55fa9993a376ed07cc3495109cbc627a1942d833068436c042ad29845b4722245f6ebf2046507d3c46ce1e8231c902323bbbe043d226a2713a9
|
7
|
+
data.tar.gz: 46bbea1467b7e6179c5ce60505d6de756acc7324eb68613d3e07e54781e4a4ef0fde50a21363569fe5052b77dcce580117aa33caccb9079b1c21d69b7ed48dee
|
data/.gitignore
CHANGED
data/.hound.yml
ADDED
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
--color
|
2
|
-
--
|
2
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
./.ruby-style.yml
|
data/.ruby-style.yml
ADDED
@@ -0,0 +1,335 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- Guardfile
|
4
|
+
- lib/fileutils.rb
|
5
|
+
- "*.gemspec"
|
6
|
+
- "db/schema.rb"
|
7
|
+
- "vendor/**/*"
|
8
|
+
UseCache: false
|
9
|
+
|
10
|
+
Metrics/LineLength:
|
11
|
+
Exclude:
|
12
|
+
- Rakefile
|
13
|
+
- "spec/**/*"
|
14
|
+
Style/BlockDelimiters:
|
15
|
+
Description: abc
|
16
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#single-line-blocks
|
17
|
+
Enabled: true
|
18
|
+
EnforcedStyle: braces_for_chaining
|
19
|
+
SupportedStyles:
|
20
|
+
- braces_for_chaining
|
21
|
+
- line_count_based
|
22
|
+
- semantic
|
23
|
+
ProceduralMethods:
|
24
|
+
- around
|
25
|
+
- before
|
26
|
+
- benchmark
|
27
|
+
- bm
|
28
|
+
- bmbm
|
29
|
+
- create
|
30
|
+
- each_with_object
|
31
|
+
- measure
|
32
|
+
- new
|
33
|
+
- realtime
|
34
|
+
- tap
|
35
|
+
- with_object
|
36
|
+
FunctionalMethods:
|
37
|
+
- let
|
38
|
+
- let!
|
39
|
+
- subject
|
40
|
+
- watch
|
41
|
+
IgnoredMethods:
|
42
|
+
- context
|
43
|
+
- describe
|
44
|
+
- it
|
45
|
+
- lambda
|
46
|
+
- proc
|
47
|
+
Style/CaseEquality:
|
48
|
+
Description: Avoid explicit use of the case equality operator(===).
|
49
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-case-equality
|
50
|
+
Enabled: false
|
51
|
+
Style/CollectionMethods:
|
52
|
+
Description: Preferred collection methods.
|
53
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
|
54
|
+
Enabled: true
|
55
|
+
PreferredMethods:
|
56
|
+
collect: map
|
57
|
+
collect!: map!
|
58
|
+
find: detect
|
59
|
+
find_all: select
|
60
|
+
reduce: inject
|
61
|
+
Style/DotPosition:
|
62
|
+
Description: Checks the position of the dot in multi-line method calls.
|
63
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
|
64
|
+
Enabled: true
|
65
|
+
EnforcedStyle: leading
|
66
|
+
SupportedStyles:
|
67
|
+
- leading
|
68
|
+
- trailing
|
69
|
+
Style/FileName:
|
70
|
+
Description: Use snake_case for source file names.
|
71
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
|
72
|
+
Enabled: false
|
73
|
+
Exclude: []
|
74
|
+
Style/GuardClause:
|
75
|
+
Description: Check for conditionals that can be replaced with guard clauses
|
76
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
|
77
|
+
Enabled: true
|
78
|
+
MinBodyLength: 1
|
79
|
+
Style/IfUnlessModifier:
|
80
|
+
Description: Favor modifier if/unless usage when you have a single-line body.
|
81
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
|
82
|
+
Enabled: false
|
83
|
+
MaxLineLength: 80
|
84
|
+
Style/OptionHash:
|
85
|
+
Description: Don't use option hashes when you can use keyword arguments.
|
86
|
+
Enabled: false
|
87
|
+
Style/NumericLiteralPrefix:
|
88
|
+
Enabled: false
|
89
|
+
Style/PercentLiteralDelimiters:
|
90
|
+
Description: Use `%`-literal delimiters consistently
|
91
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
|
92
|
+
Enabled: false
|
93
|
+
PreferredDelimiters:
|
94
|
+
"%": "()"
|
95
|
+
"%i": "[]"
|
96
|
+
"%q": "()"
|
97
|
+
"%Q": "()"
|
98
|
+
"%r": "{}"
|
99
|
+
"%s": "()"
|
100
|
+
"%w": "[]"
|
101
|
+
"%W": "[]"
|
102
|
+
"%x": "()"
|
103
|
+
Style/PredicateName:
|
104
|
+
Description: Check the names of predicate methods.
|
105
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
|
106
|
+
Enabled: true
|
107
|
+
NamePrefix:
|
108
|
+
- is_
|
109
|
+
- has_
|
110
|
+
- have_
|
111
|
+
NamePrefixBlacklist:
|
112
|
+
- is_
|
113
|
+
Exclude:
|
114
|
+
- spec/**/*
|
115
|
+
Style/RaiseArgs:
|
116
|
+
Description: Checks the arguments passed to raise/fail.
|
117
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
|
118
|
+
Enabled: false
|
119
|
+
EnforcedStyle: exploded
|
120
|
+
SupportedStyles:
|
121
|
+
- compact
|
122
|
+
- exploded
|
123
|
+
Style/RegexpLiteral:
|
124
|
+
Description: Checks if uses of regexps match the configured preference.
|
125
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-r
|
126
|
+
Enabled: true
|
127
|
+
EnforcedStyle: mixed
|
128
|
+
SupportedStyles:
|
129
|
+
- mixed
|
130
|
+
- percent_r
|
131
|
+
- slashes
|
132
|
+
AllowInnerSlashes: false
|
133
|
+
Style/SignalException:
|
134
|
+
Description: Checks for proper usage of fail and raise.
|
135
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
|
136
|
+
Enabled: false
|
137
|
+
EnforcedStyle: semantic
|
138
|
+
SupportedStyles:
|
139
|
+
- only_raise
|
140
|
+
- only_fail
|
141
|
+
- semantic
|
142
|
+
Style/SingleLineBlockParams:
|
143
|
+
Description: Enforces the names of some block params.
|
144
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
|
145
|
+
Enabled: false
|
146
|
+
Methods:
|
147
|
+
- reduce:
|
148
|
+
- a
|
149
|
+
- e
|
150
|
+
- inject:
|
151
|
+
- a
|
152
|
+
- e
|
153
|
+
Style/SingleLineMethods:
|
154
|
+
Description: Avoid single-line methods.
|
155
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
|
156
|
+
Enabled: false
|
157
|
+
AllowIfMethodIsEmpty: true
|
158
|
+
Style/StringLiterals:
|
159
|
+
Description: Checks if uses of quotes match the configured preference.
|
160
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
|
161
|
+
Enabled: true
|
162
|
+
EnforcedStyle: single_quotes
|
163
|
+
SupportedStyles:
|
164
|
+
- single_quotes
|
165
|
+
- double_quotes
|
166
|
+
Style/StringLiteralsInInterpolation:
|
167
|
+
Description: Checks if uses of quotes inside expressions in interpolated strings
|
168
|
+
match the configured preference.
|
169
|
+
Enabled: true
|
170
|
+
EnforcedStyle: single_quotes
|
171
|
+
SupportedStyles:
|
172
|
+
- single_quotes
|
173
|
+
- double_quotes
|
174
|
+
Style/TrailingCommaInLiteral:
|
175
|
+
Description: Checks for trailing comma in parameter lists and literals.
|
176
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
|
177
|
+
Enabled: false
|
178
|
+
EnforcedStyleForMultiline: no_comma
|
179
|
+
SupportedStyles:
|
180
|
+
- comma
|
181
|
+
- no_comma
|
182
|
+
Style/TrailingCommaInArguments:
|
183
|
+
Description: Checks for trailing comma in parameter lists and literals.
|
184
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas
|
185
|
+
Enabled: false
|
186
|
+
EnforcedStyleForMultiline: no_comma
|
187
|
+
SupportedStyles:
|
188
|
+
- comma
|
189
|
+
- no_comma
|
190
|
+
Style/TrivialAccessors:
|
191
|
+
Description: Prefer attr_* methods to trivial readers/writers.
|
192
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#attr_family
|
193
|
+
Enabled: false
|
194
|
+
ExactNameMatch: true
|
195
|
+
AllowPredicates: false
|
196
|
+
AllowDSLWriters: false
|
197
|
+
IgnoreClassMethods: false
|
198
|
+
Whitelist:
|
199
|
+
- to_ary
|
200
|
+
- to_a
|
201
|
+
- to_c
|
202
|
+
- to_enum
|
203
|
+
- to_h
|
204
|
+
- to_hash
|
205
|
+
- to_i
|
206
|
+
- to_int
|
207
|
+
- to_io
|
208
|
+
- to_open
|
209
|
+
- to_path
|
210
|
+
- to_proc
|
211
|
+
- to_r
|
212
|
+
- to_regexp
|
213
|
+
- to_str
|
214
|
+
- to_s
|
215
|
+
- to_sym
|
216
|
+
Style/ZeroLengthPredicate:
|
217
|
+
Exclude:
|
218
|
+
- lib/memfs/file.rb
|
219
|
+
Metrics/AbcSize:
|
220
|
+
Description: A calculated magnitude based on number of assignments, branches, and
|
221
|
+
conditions.
|
222
|
+
Enabled: false
|
223
|
+
Max: 15
|
224
|
+
Metrics/ClassLength:
|
225
|
+
Description: Avoid classes longer than 100 lines of code.
|
226
|
+
Enabled: false
|
227
|
+
CountComments: false
|
228
|
+
Max: 100
|
229
|
+
Metrics/ModuleLength:
|
230
|
+
CountComments: false
|
231
|
+
Max: 100
|
232
|
+
Description: Avoid modules longer than 100 lines of code.
|
233
|
+
Enabled: false
|
234
|
+
Metrics/CyclomaticComplexity:
|
235
|
+
Description: A complexity metric that is strongly correlated to the number of test
|
236
|
+
cases needed to validate a method.
|
237
|
+
Enabled: false
|
238
|
+
Max: 6
|
239
|
+
Metrics/MethodLength:
|
240
|
+
Description: Avoid methods longer than 10 lines of code.
|
241
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
|
242
|
+
Enabled: false
|
243
|
+
CountComments: false
|
244
|
+
Max: 10
|
245
|
+
Metrics/ParameterLists:
|
246
|
+
Description: Avoid parameter lists longer than three or four parameters.
|
247
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
|
248
|
+
Enabled: false
|
249
|
+
Max: 5
|
250
|
+
CountKeywordArgs: true
|
251
|
+
Metrics/PerceivedComplexity:
|
252
|
+
Description: A complexity metric geared towards measuring complexity for a human
|
253
|
+
reader.
|
254
|
+
Enabled: false
|
255
|
+
Max: 7
|
256
|
+
Lint/AssignmentInCondition:
|
257
|
+
Description: Don't use assignment in conditions.
|
258
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
|
259
|
+
Enabled: false
|
260
|
+
AllowSafeAssignment: true
|
261
|
+
Style/InlineComment:
|
262
|
+
Description: Avoid inline comments.
|
263
|
+
Enabled: false
|
264
|
+
Style/AccessorMethodName:
|
265
|
+
Description: Check the naming of accessor methods for get_/set_.
|
266
|
+
Enabled: false
|
267
|
+
Style/Alias:
|
268
|
+
Description: Use alias_method instead of alias.
|
269
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
|
270
|
+
Enabled: false
|
271
|
+
Style/Documentation:
|
272
|
+
Description: Document classes and non-namespace modules.
|
273
|
+
Enabled: false
|
274
|
+
Style/DoubleNegation:
|
275
|
+
Description: Checks for uses of double negation (!!).
|
276
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
|
277
|
+
Enabled: false
|
278
|
+
Style/EachWithObject:
|
279
|
+
Description: Prefer `each_with_object` over `inject` or `reduce`.
|
280
|
+
Enabled: false
|
281
|
+
Style/EmptyLiteral:
|
282
|
+
Description: Prefer literals to Array.new/Hash.new/String.new.
|
283
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
|
284
|
+
Enabled: false
|
285
|
+
Style/ModuleFunction:
|
286
|
+
Description: Checks for usage of `extend self` in modules.
|
287
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
|
288
|
+
Enabled: false
|
289
|
+
Style/MultilineOperationIndentation:
|
290
|
+
Description: Checks indentation of binary operations that span more than
|
291
|
+
one line.
|
292
|
+
Enabled: false
|
293
|
+
EnforcedStyle: aligned
|
294
|
+
SupportedStyles:
|
295
|
+
- aligned
|
296
|
+
- indented
|
297
|
+
Style/OneLineConditional:
|
298
|
+
Description: Favor the ternary operator(?:) over if/then/else/end constructs.
|
299
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
|
300
|
+
Enabled: false
|
301
|
+
Style/PerlBackrefs:
|
302
|
+
Description: Avoid Perl-style regex back references.
|
303
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
|
304
|
+
Enabled: false
|
305
|
+
Style/Send:
|
306
|
+
Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
|
307
|
+
may overlap with existing methods.
|
308
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
|
309
|
+
Enabled: false
|
310
|
+
Style/SpecialGlobalVars:
|
311
|
+
Description: Avoid Perl-style global variables.
|
312
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
|
313
|
+
Enabled: false
|
314
|
+
Style/VariableInterpolation:
|
315
|
+
Description: Don't interpolate global, instance and class variables directly in
|
316
|
+
strings.
|
317
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
|
318
|
+
Enabled: false
|
319
|
+
Style/WhenThen:
|
320
|
+
Description: Use when x then ... for one-line cases.
|
321
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
|
322
|
+
Enabled: false
|
323
|
+
Lint/EachWithObjectArgument:
|
324
|
+
Description: Check for immutable argument given to each_with_object.
|
325
|
+
Enabled: true
|
326
|
+
Lint/HandleExceptions:
|
327
|
+
Description: Don't suppress exception.
|
328
|
+
StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
|
329
|
+
Enabled: false
|
330
|
+
Lint/LiteralInCondition:
|
331
|
+
Description: Checks of literals used in conditions.
|
332
|
+
Enabled: false
|
333
|
+
Lint/LiteralInInterpolation:
|
334
|
+
Description: Checks for literals used in interpolation.
|
335
|
+
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 1.0.0
|
4
|
+
|
5
|
+
:warning: This version drops support for Ruby 1.9.
|
6
|
+
|
7
|
+
* ADD: Support for Ruby 2.4.0
|
8
|
+
* ADD: Support for _Pathname_ in `Dir.glob` (PR #21 by @craigw)
|
9
|
+
* ADD: `MemFs.halt` to switch back to the real file-system (PR #24 by @thsur)
|
10
|
+
* ADD: Basic support for `IO.write` (PR #20 by @rmm5t)
|
11
|
+
* FIX: Reset the file position when reopened (PR #23 by @jimpo)
|
12
|
+
* FIX: Ignore trailing slashes when searching an entry (issue #26)
|
13
|
+
* FIX: Making `File` inherit from `IO` to fix 3rd-party related issues
|
14
|
+
* FIX: Ensure `File.new` on a symlink raises if target is absent
|
4
15
|
|
5
16
|
## 0.5.0
|
6
17
|
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
![MemFs Logo](https://raw.github.com/simonc/memfs/master/memfs.png)
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/memfs.
|
4
|
-
[![Build Status](https://
|
5
|
-
[![Code Climate](https://codeclimate.com/github/simonc/memfs.
|
6
|
-
[![Coverage Status](https://coveralls.io/repos/simonc/memfs/badge.
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/memfs.svg)](https://badge.fury.io/rb/memfs)
|
4
|
+
[![Build Status](https://api.travis-ci.org/simonc/memfs.svg?branch=master)](http://travis-ci.org/simonc/memfs)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/simonc/memfs/badges/gpa.svg)](https://codeclimate.com/github/simonc/memfs)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/github/simonc/memfs/badge.svg?branch=master)](https://coveralls.io/github/simonc/memfs?branch=master)
|
7
7
|
|
8
8
|
MemFs is an in-memory filesystem that can be used for your tests.
|
9
9
|
|
@@ -161,13 +161,14 @@ end
|
|
161
161
|
|
162
162
|
## Requirements
|
163
163
|
|
164
|
-
* Ruby
|
164
|
+
* Ruby 2.0 or newer
|
165
165
|
|
166
166
|
## Known issues
|
167
167
|
|
168
168
|
* MemFs doesn't implement IO so methods like `FileUtils.copy_stream` and `IO.write` are still the originals.
|
169
169
|
* Similarly, MemFs doesn't implement Kernel, so don't use a naked `open()` call. This uses the `Kernel` class via `method_missing`, which MemFs will not intercept.
|
170
170
|
* Pipes and Sockets are not handled for now.
|
171
|
+
* ~`require "pp"` will raise a _superclass mismatch_ exception since MemFs::File does not inherit from IO. The best thing to do is to require pp _before_ MemFs.~
|
171
172
|
|
172
173
|
## TODO
|
173
174
|
|
data/lib/memfs.rb
CHANGED
@@ -22,6 +22,9 @@ module MemFs
|
|
22
22
|
# Keeps track of the original Ruby File class.
|
23
23
|
OriginalFile = ::File
|
24
24
|
|
25
|
+
# Keeps track of the original Ruby IO class.
|
26
|
+
OriginalIO = ::IO
|
27
|
+
|
25
28
|
require 'memfs/file_system'
|
26
29
|
require 'memfs/dir'
|
27
30
|
require 'memfs/file'
|
@@ -70,16 +73,18 @@ module MemFs
|
|
70
73
|
#
|
71
74
|
# @see #deactivate!
|
72
75
|
# @return nothing.
|
73
|
-
def activate!
|
76
|
+
def activate!(clear: true)
|
74
77
|
Object.class_eval do
|
75
78
|
remove_const :Dir
|
76
79
|
remove_const :File
|
80
|
+
remove_const :IO
|
77
81
|
|
78
82
|
const_set :Dir, MemFs::Dir
|
83
|
+
const_set :IO, MemFs::IO
|
79
84
|
const_set :File, MemFs::File
|
80
85
|
end
|
81
86
|
|
82
|
-
MemFs::FileSystem.instance.clear!
|
87
|
+
MemFs::FileSystem.instance.clear! if clear
|
83
88
|
end
|
84
89
|
module_function :activate!
|
85
90
|
|
@@ -93,13 +98,35 @@ module MemFs
|
|
93
98
|
Object.class_eval do
|
94
99
|
remove_const :Dir
|
95
100
|
remove_const :File
|
101
|
+
remove_const :IO
|
96
102
|
|
97
103
|
const_set :Dir, MemFs::OriginalDir
|
104
|
+
const_set :IO, MemFs::OriginalIO
|
98
105
|
const_set :File, MemFs::OriginalFile
|
99
106
|
end
|
100
107
|
end
|
101
108
|
module_function :deactivate!
|
102
109
|
|
110
|
+
# Switches back to the original file system, calls the given block (if any),
|
111
|
+
# and switches back afterwards.
|
112
|
+
#
|
113
|
+
# If a block is given, all file & dir operations (like reading dir contents or
|
114
|
+
# requiring files) will operate on the original fs.
|
115
|
+
#
|
116
|
+
# @example
|
117
|
+
# MemFs.halt do
|
118
|
+
# puts Dir.getwd
|
119
|
+
# end
|
120
|
+
# @return nothing
|
121
|
+
def halt
|
122
|
+
deactivate!
|
123
|
+
|
124
|
+
yield if block_given?
|
125
|
+
ensure
|
126
|
+
activate!(clear: false)
|
127
|
+
end
|
128
|
+
module_function :halt
|
129
|
+
|
103
130
|
# Creates a file and all its parent directories.
|
104
131
|
#
|
105
132
|
# @param path: The path of the file to create.
|