Class Pathname
In: lib/more/facets/pathname.rb
Parent: Object

Methods

/   []   empty?   glob   glob_first   home   null   root   rootname   split_root   work  

External Aliases

+ -> /
  Try to get this into standard Pathname class.

Public Class methods

Active path separator.

  p1 = Pathname.new('/')
  p2 = p1 / 'usr' / 'share'   #=> Pathname:/usr/share

[Source]

    # File lib/more/facets/pathname.rb, line 41
41:   def self./(path)
42:     new(path)
43:   end

Alternate to Pathname#new.

  Pathname['/usr/share']

[Source]

    # File lib/more/facets/pathname.rb, line 32
32:   def self.[](path)
33:     new(path)
34:   end

Home constant for building paths from root directory onward.

TODO: Pathname#home needs to be more robust.

[Source]

    # File lib/more/facets/pathname.rb, line 54
54:   def self.home
55:     Pathname.new('~')
56:   end

Platform dependent null device.

[Source]

    # File lib/more/facets/pathname.rb, line 71
71:   def self.null
72:     case RUBY_PLATFORM
73:     when /mswin/i
74:       'NUL'
75:     when /amiga/i
76:       'NIL:'
77:     when /openvms/i
78:       'NL:'
79:     else
80:       '/dev/null'
81:     end
82:   end

Root constant for building paths from root directory onward.

[Source]

    # File lib/more/facets/pathname.rb, line 46
46:   def self.root
47:     Pathname.new('/')
48:   end

Work constant for building paths from root directory onward.

[Source]

    # File lib/more/facets/pathname.rb, line 60
60:   def self.work
61:     Pathname.new('.')
62:   end

Public Instance methods

[Source]

     # File lib/more/facets/pathname.rb, line 155
155:   def empty?
156:     Dir.glob(::File.join(self.to_s, '*')).empty?
157:   end

[Source]

     # File lib/more/facets/pathname.rb, line 128
128:   def glob(match, *opts)
129:     flags = 0
130:     opts.each do |opt|
131:       case opt when Symbol, String
132:         flags += File.const_get("FNM_#{opt}".upcase)
133:       else
134:         flags += opt
135:       end
136:     end
137:     Dir.glob(::File.join(self.to_s, match), flags).collect{ |m| self.class.new(m) }
138:   end

[Source]

     # File lib/more/facets/pathname.rb, line 141
141:   def glob_first(match, *opts)
142:     flags = 0
143:     opts.each do |opt|
144:       case opt when Symbol, String
145:         flags += ::File.const_get("FNM_#{opt}".upcase)
146:       else
147:         flags += opt
148:       end
149:     end
150:     file = ::Dir.glob(::File.join(self.to_s, match), flags).first
151:     file ? self.class.new(file) : nil
152:   end

[Source]

    # File lib/more/facets/pathname.rb, line 85
85:   def rootname
86:     self.class.new(File.rootname(to_s))
87:   end

[Source]

     # File lib/more/facets/pathname.rb, line 122
122:   def split_root
123:     head, tail = *::File.split_root(to_s)
124:     [self.class.new(head), self.class.new(tail)]
125:   end

[Validate]