Class: MockFS::FileAdapter
- Inherits:
-
Object
- Object
- MockFS::FileAdapter
show all
- Extended by:
- Adapter
- Defined in:
- lib/mockfs.rb
Overview
Defined Under Namespace
Classes: Mode
Class Method Summary
collapse
Methods included from Adapter
method_missing, node, respond_to?
Class Method Details
.chmod(perms, *filenames) ⇒ Object
243
244
245
|
# File 'lib/mockfs.rb', line 243
def self.chmod( perms, *filenames )
node( filenames.first ).permissions = perms
end
|
.directory?(file_name) ⇒ Boolean
247
248
249
250
251
252
253
|
# File 'lib/mockfs.rb', line 247
def self.directory?( file_name )
begin
node( file_name ).is_a? MockFileSystem::MockDir
rescue Errno::ENOENT
false
end
end
|
.exist?(filename) ⇒ Boolean
Also known as:
exists?
256
257
258
259
260
261
262
263
|
# File 'lib/mockfs.rb', line 256
def exist?( filename )
begin
node( filename )
true
rescue Errno::ENOENT
false
end
end
|
.file?(file_name) ⇒ Boolean
268
269
270
271
272
273
274
|
# File 'lib/mockfs.rb', line 268
def self.file?( file_name )
begin
node( file_name ).is_a? MockFileSystem::MockFile
rescue Errno::ENOENT
false
end
end
|
.mock_file(fd, mode) ⇒ Object
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
# File 'lib/mockfs.rb', line 276
def self.mock_file( fd, mode ) if mode.read_only?
mock_file = node( fd )
raise Errno::EACCES if mock_file and !mock_file.readable?
else
path = Path.new( fd ).absolute
dir = node( path.parent )
if mode.append?
mock_file = node( fd )
else
mock_file = MockFileSystem::MockFile.new( dir, path.node, '' )
end
end
mock_file
end
|
.open(fd, mode_string = File::RDONLY, &action) ⇒ Object
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
# File 'lib/mockfs.rb', line 292
def self.open( fd, mode_string = File::RDONLY, &action )
mode = Mode.new mode_string
mock_file = mock_file( fd, mode )
mock_file.pos = mock_file.size if mode.append?
if action
result = action.call( mock_file )
mock_file.rewind
if !mode.read_only? and !mode.append?
mock_file.parent[Path.new( fd ).absolute.node] = mock_file
end
result
else
mock_file
end
end
|
.read(name) ⇒ Object
308
309
310
311
312
|
# File 'lib/mockfs.rb', line 308
def self.read( name )
mfile = node name
raise Errno::EISDIR if mfile.is_a? MockFileSystem::MockDir
mfile.read
end
|