Class: Dir

Inherits:
Object
  • Object
show all
Defined in:
lib/torquebox/vfs/ext/dir.rb

Overview

Copyright 2008-2011 Red Hat, Inc, and individual contributors.

This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this software; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site: www.fsf.org.

Class Method Summary collapse

Class Method Details

.[](*pattern) ⇒ Object



55
56
57
# File 'lib/torquebox/vfs/ext/dir.rb', line 55

def [](*pattern)
  self.glob( pattern )
end

.chdir(*args, &block) ⇒ Object



64
65
66
67
# File 'lib/torquebox/vfs/ext/dir.rb', line 64

def chdir(*args, &block)
  raise "You shouldn't use chdir, but if you must, pass a block!" unless block_given?
  chdir_before_vfs( *args.map{ |x| File.name_without_vfs(x) }, &block )
end

.chdir_before_vfsObject



26
# File 'lib/torquebox/vfs/ext/dir.rb', line 26

alias_method :chdir_before_vfs, :chdir

.entries(path, options = {}) ⇒ Object

1.9 has an optional, undocumented options arg that appears to be used for encoding. We’ll ignore it for now, since JRuby does as well. (see org.jruby.RubyDir.java)



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/torquebox/vfs/ext/dir.rb', line 99

def entries(path, options = {})
  if ( ::File.exist_without_vfs?( path ) )
    return entries_before_vfs(path)
  end
  vfs_dir = org.jboss.vfs::VFS.child( File.path_to_str(path) )
  # Delegate to original entries if passed a nonexistent file
  unless vfs_dir.exists?
    return entries_before_vfs( path )
  end
  [ '.', '..' ] + vfs_dir.children.collect{|e| e.name }
end

.entries_before_vfsObject



28
# File 'lib/torquebox/vfs/ext/dir.rb', line 28

alias_method :entries_before_vfs, :entries

.foreach(path, &block) ⇒ Object



111
112
113
114
# File 'lib/torquebox/vfs/ext/dir.rb', line 111

def foreach(path, &block)
  enum = entries(path).each(&block)
  block_given? ? nil : enum
end

.foreach_before_vfsObject



29
# File 'lib/torquebox/vfs/ext/dir.rb', line 29

alias_method :foreach_before_vfs, :foreach

.glob(pattern, flags = 0, &block) ⇒ Object



59
60
61
62
# File 'lib/torquebox/vfs/ext/dir.rb', line 59

def glob(pattern, flags=0, &block)
  patterns = [pattern].flatten
  patterns.collect { |pattern| glob_one( pattern, flags, &block ) }.flatten
end

.glob_before_vfsObject



23
# File 'lib/torquebox/vfs/ext/dir.rb', line 23

alias_method :glob_before_vfs, :glob

.mkdir(path, mode = 0777) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/torquebox/vfs/ext/dir.rb', line 76

def mkdir(path, mode=0777)
  mkdir_before_vfs( File.name_without_vfs(path), mode )
rescue Errno::ENOTDIR => e
  path = TorqueBox::VFS.writable_path_or_error( File.path_to_str(path), e )
  mkdir_before_vfs( path, mode )
rescue Errno::ENOENT => e
  path = TorqueBox::VFS.writable_path_or_error( File.path_to_str(path), e )
  mkdir_before_vfs( path, mode )
end

.mkdir_before_vfsObject



24
# File 'lib/torquebox/vfs/ext/dir.rb', line 24

alias_method :mkdir_before_vfs, :mkdir

.new(string, options = nil) ⇒ Object

1.8: new( dirname ) 1.9: new( dirname, <, :encoding => enc> ) We currently ignore the encoding.



89
90
91
92
93
94
# File 'lib/torquebox/vfs/ext/dir.rb', line 89

def new(string, options = nil)
  if ( ::File.exist_without_vfs?( string ) )
    return new_before_vfs( string )
  end
  TorqueBox::VFS::Dir.new( string )
end

.new_before_vfsObject



27
# File 'lib/torquebox/vfs/ext/dir.rb', line 27

alias_method :new_before_vfs, :new

.open(str, options = nil, &block) ⇒ Object

1.8: open( dirname ) 1.9: open( dirname, <, :encoding => enc> ) We currently ignore the encoding.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/torquebox/vfs/ext/dir.rb', line 34

def open(str, options = nil, &block)
  if ( ::File.exist_without_vfs?( str ) )
    return open_before_vfs(str,&block)
  end
  #puts "open(#{str})"
  result = dir = TorqueBox::VFS::Dir.new( str )
  #puts "  result = #{result}"
  unless result.exists?
    return open_before_vfs(str,&block)
  end
  if block
    begin
      result = block.call(dir)
    ensure
      dir.close
    end
  end
  #puts "open(#{str}) return #{result}"
  result
end

.open_before_vfsObject



22
# File 'lib/torquebox/vfs/ext/dir.rb', line 22

alias_method :open_before_vfs, :open

.rmdir(path) ⇒ Object Also known as: unlink, delete



69
70
71
72
# File 'lib/torquebox/vfs/ext/dir.rb', line 69

def rmdir(path)
  name = File.name_without_vfs(path)
  rmdir_before_vfs(name)
end

.rmdir_before_vfsObject



25
# File 'lib/torquebox/vfs/ext/dir.rb', line 25

alias_method :rmdir_before_vfs, :rmdir