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
247
248
249
|
# File 'lib/mockfs.rb', line 247
def self.chmod( perms, *filenames )
node( filenames.first ).permissions = perms
end
|
.directory?(file_name) ⇒ Boolean
251
252
253
254
255
256
257
|
# File 'lib/mockfs.rb', line 251
def self.directory?( file_name )
begin
node( file_name ).is_a? MockFileSystem::MockDir
rescue Errno::ENOENT
false
end
end
|
.dirname(file_name) ⇒ Object
259
260
261
|
# File 'lib/mockfs.rb', line 259
def self.dirname( file_name )
File.dirname file_name
end
|
.exist?(filename) ⇒ Boolean
Also known as:
exists?
264
265
266
267
268
269
270
271
|
# File 'lib/mockfs.rb', line 264
def exist?( filename )
begin
node( filename )
true
rescue Errno::ENOENT
false
end
end
|
.file?(file_name) ⇒ Boolean
276
277
278
279
280
281
282
|
# File 'lib/mockfs.rb', line 276
def self.file?( file_name )
begin
node( file_name ).is_a? MockFileSystem::MockFile
rescue Errno::ENOENT
false
end
end
|
.mock_file(fd, mode) ⇒ Object
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
# File 'lib/mockfs.rb', line 284
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
# File 'lib/mockfs.rb', line 300
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
316
317
318
319
320
321
322
|
# File 'lib/mockfs.rb', line 316
def self.read( name )
mfile = node name
raise Errno::EISDIR if mfile.is_a? MockFileSystem::MockDir
contents = mfile.read
mfile.rewind
contents
end
|