Parent

Pathname

Public Class Methods

/(path) click to toggle source

Active path separator.

  p1 = Pathname.new('/')
  p2 = p1 / 'usr' / 'share'   #=> Pathname:/usr/share
    # File lib/more/facets/pathname.rb, line 45
45:   def self./(path)
46:     new(path)
47:   end
[](path) click to toggle source

Alternate to Pathname#new.

  Pathname['/usr/share']
    # File lib/more/facets/pathname.rb, line 36
36:   def self.[](path)
37:     new(path)
38:   end
home() click to toggle source

Home constant for building paths from root directory onward.

TODO: Pathname#home needs to be more robust.

    # File lib/more/facets/pathname.rb, line 58
58:   def self.home
59:     Pathname.new('~')
60:   end
null() click to toggle source

Platform dependent null device.

    # File lib/more/facets/pathname.rb, line 75
75:   def self.null
76:     case RUBY_PLATFORM
77:     when /mswin/
78:       'NUL'
79:     when /amiga/
80:       'NIL:'
81:     when /openvms/
82:       'NL:'
83:     else
84:       '/dev/null'
85:     end
86:   end
root() click to toggle source

Root constant for building paths from root directory onward.

    # File lib/more/facets/pathname.rb, line 50
50:   def self.root
51:     Pathname.new('/')
52:   end
work() click to toggle source

Work constant for building paths from root directory onward.

    # File lib/more/facets/pathname.rb, line 64
64:   def self.work
65:     Pathname.new('.')
66:   end

Public Instance Methods

empty?() click to toggle source
     # File lib/more/facets/pathname.rb, line 141
141:   def empty?
142:     Dir.glob(::File.join(to_s, '*')).empty?
143:   end
glob(match, *opts) click to toggle source

Glob pathnames.

     # File lib/more/facets/pathname.rb, line 100
100:   def glob(match, *opts)
101:     flags = glob_flags(opts)
102:     Dir.glob(::File.join(self.to_s, match), flags).collect{ |m| self.class.new(m) }
103:   end
glob_first(match, *opts) click to toggle source

Return the first glob match.

DEPRECATE: While slightly faster then glob().first, not really worth it unless this can be rewritten to shortcut on first match (using fnmatch?). In wich case, is there a better name for this method?

     # File lib/more/facets/pathname.rb, line 110
110:   def glob_first(match, *opts)
111:     flags = glob_flags(opts)
112:     file = ::Dir.glob(::File.join(self.to_s, match), flags).first
113:     file ? self.class.new(file) : nil
114:   end
glob_relative(match, *opts) click to toggle source

Return globbed matches with pathnames relative to the current pathname.

     # File lib/more/facets/pathname.rb, line 117
117:   def glob_relative(match, *opts)
118:     flags = glob_flags(opts)
119:     files = Dir.glob(::File.join(self.to_s, match), flags)
120:     files = files.map{ |f| f.sub(self.to_s.chomp('/') + '/', '') }
121:     files.collect{ |m| self.class.new(m) }
122:   end
outofdate?(*sources) click to toggle source
     # File lib/more/facets/pathname.rb, line 151
151:   def outofdate?(*sources)
152:     ::FileUtils.outofdate?(to_s, sources.flatten)
153:   end
rootname() click to toggle source
    # File lib/more/facets/pathname.rb, line 89
89:   def rootname
90:     self.class.new(File.rootname(to_s))
91:   end
split_root() click to toggle source
    # File lib/more/facets/pathname.rb, line 94
94:   def split_root
95:     head, tail = *::File.split_root(to_s)
96:     [self.class.new(head), self.class.new(tail)]
97:   end
uptodate?(*sources) click to toggle source
     # File lib/more/facets/pathname.rb, line 146
146:   def uptodate?(*sources)
147:     ::FileUtils.uptodate?(to_s, sources.flatten)
148:   end
visit => yield each file visit(all: true) => yield visited directories as well visit(hidden: true) => yield hidden files and directories as well click to toggle source

Recursively visit a directory located by its path, yielding each resource as its full matching pathname object. If called on a file, yield the file.

Example use case:

  # get rid of any file but *.haml within app/**/*
  Pathname.new("app").visit do |f|
    FileUtils.rm_f(f) unless f.to_s =~ /\.haml$/
    puts "!!! deleting #{f}"
  end 

CREDIT: Jean-Denis Vauguet

     # File lib/more/facets/pathname.rb, line 172
172:   def visit(options = {:all => false, :hidden => false})
173:     if self.directory?
174:       children.each do |entry|
175:         next if entry.basename.to_s[0] == "." && !options[:hidden]
176:         yield(entry) unless entry.directory? && !options[:all]
177:         #entry.visit(:all => options[:all]) { |sub_entry| yield sub_entry } if entry.directory?
178:         entry.visit(:all => options[:all], :hidden => options[:hidden]) do |sub_entry|
179:           yield(sub_entry)
180:         end if entry.directory?
181:       end
182:     else
183:       yield self
184:     end
185:   end

Private Instance Methods

glob_flags(opts) click to toggle source
     # File lib/more/facets/pathname.rb, line 126
126:   def glob_flags(opts)
127:     flags = 0
128:     opts.each do |opt|
129:       case opt when Symbol, String
130:         flags += ::File.const_get("FNM_#{opt}".upcase)
131:       else
132:         flags += opt
133:       end
134:     end
135:     flags
136:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.