Class: MockFS::FileUtilsAdapter

Inherits:
Object
  • Object
show all
Extended by:
Adapter
Defined in:
lib/mockfs.rb

Overview

:nodoc:

Class Method Summary collapse

Methods included from Adapter

method_missing, node, respond_to?

Class Method Details

.cp(src, dest, options = {}) ⇒ Object



348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/mockfs.rb', line 348

def self.cp( src, dest, options = {} )
  file = node( src ).clone
  dest_path = Path.new( dest ).absolute
  if MockFS.file.exist?( dest )
    maybe_dest_dir = node dest_path
    if maybe_dest_dir.is_a? MockFileSystem::MockDir
      dest_path << ( '/' + Path.new( src ).absolute.node )
    end
  end
  dest_dir = node dest_path.parent
  dest_dir[dest_path.node] = file
  file.name = dest_path.node
  file.parent = dest_dir
end

.mkpath(path) ⇒ Object



363
# File 'lib/mockfs.rb', line 363

def self.mkpath( path ); MockFS.fill_path( path ); end

.mv(src, dest, options = {}) ⇒ Object Also known as: move



366
367
368
369
# File 'lib/mockfs.rb', line 366

def mv( src, dest, options = {} )
  cp( src, dest, options )
  MockFS.file.delete( src )
end

.touch(file) ⇒ Object



374
375
376
377
378
379
380
381
382
383
# File 'lib/mockfs.rb', line 374

def self.touch( file )
  begin
    node( file ).mtime = Time.now
  rescue Errno::ENOENT
    path = Path.new( file ).absolute
    parent_dir = node( path.parent )
    file = MockFileSystem::MockFile.new( parent_dir, path.node, '' )
    parent_dir[path.node] = file
  end
end