class Pathname

Public Instance Methods

components() click to toggle source

Split a pathname up based on the individual path components.

# File lib/lsync/directory.rb, line 27
def components
        return to_s.split(SEPARATOR_PAT)
end
depth() click to toggle source

Returns the number of path components in a normalised fashion.

We need to work with a cleanpath to get an accurate depth:

"", "/" => 0
"bob" => 1
"bob/dole" => 2
"/bob/dole" => 2
# File lib/lsync/directory.rb, line 47
def depth
        bits = cleanpath.to_s.split(SEPARATOR_PAT)

        bits.delete("")
        bits.delete(".")

        return bits.size
end
normalize_trailing_slash() click to toggle source

Add a trailing slash to the path if it doesn't already exist.

# File lib/lsync/directory.rb, line 32
def normalize_trailing_slash
        if to_s.match(/\/$/)
                return self
        else
                return self.class.new(to_s + "/")
        end
end