class ElFinderFtp::Pathname
Attributes
adapter[R]
path[R]
root[R]
Public Class Methods
new(adapter_or_root, path = '.')
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 10 def initialize(adapter_or_root, path = '.') @adapter = adapter_or_root.is_a?(ElFinderFtp::Pathname) ? adapter_or_root.adapter : adapter_or_root @root = path.is_a?(ElFinderFtp::Pathname) ? path.root : FtpPathname.new(@adapter, '/') if path.is_a?(ElFinderFtp::Pathname) @path = path.path elsif path.is_a?(ElFinderFtp::FtpPathname) @path = path else @path = FtpPathname.new(@adapter, path) end if absolute? if @path.cleanpath.to_s.start_with?(@root.to_s) @path = FtpPathname.new( @adapter, @path.to_s.slice((@root.to_s.length)..-1), @path.attrs) elsif @path.cleanpath.to_s.start_with?(@root.realpath.to_s) @path = FtpPathname.new( @adapter, @path.to_s.slice((@root.realpath.to_s.length)..-1), @path.attrs) else raise SecurityError, "Absolute paths are not allowed" end end raise SecurityError, "Paths outside the root are not allowed" if outside_of_root? end
Public Instance Methods
+(other)
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 36 def +(other) if other.is_a? ::ElFinderFtp::Pathname other = other.path end self.class.new(@adapter, @path + other) end
absolute?()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 49 def absolute? @path.absolute? end
basename(*args)
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 79 def basename(*args) @path.basename(*args) end
basename_sans_extension()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 84 def basename_sans_extension @path.basename(@path.extname) end
child_directories(with_directory=true)
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 110 def child_directories(with_directory=true) adapter.children(self, with_directory).select{ |child| child.directory? }.map{|e| self.class.new(@adapter, e)} end
children(with_directory=true)
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 121 def children(with_directory=true) adapter.children(self, with_directory).map{|e| self.class.new(@adapter, e)} end
cleanpath()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 69 def cleanpath fullpath.cleanpath end
dirname()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 94 def dirname self.class.new(@adapter, @path.dirname) end
duplicate()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 147 def duplicate _basename = basename_sans_extension copy = 1 if _basename.to_s =~ /^(.*) copy (\d+)$/ _basename = $1 copy = $2.to_i end begin new_file = self.class.new(@adapter, dirname + "#{_basename} copy #{copy}#{extname}") copy += 1 end while new_file.exist? new_file end
extname()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 99 def extname @path.nil? ? '' : @path.extname end
files(with_directory=true)
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 115 def files(with_directory=true) adapter.children(self, with_directory).select{ |child| child.file? }.map{|e| self.class.new(@adapter, e)} end
fullpath()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 64 def fullpath @fullpath ||= (@path.nil? ? @root : @root + @path) end
is_root?()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 44 def is_root? @path.to_s == '.' end
outside_of_root?()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 59 def outside_of_root? !cleanpath.to_s.start_with?(@root.to_s) end
realpath()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 74 def realpath fullpath.realpath end
relative?()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 54 def relative? @path.relative? end
relative_to(other)
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 131 def relative_to(other) @path.relative_path_from(other) end
rename(to)
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 162 def rename(to) to = self.class.new(@adapter, to) realpath.rename(to.fullpath.to_s) to end
to_s()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 104 def to_s cleanpath.to_s end
Also aliased as: to_str
touch(options = {})
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 126 def touch(options = {}) adapter.touch(cleanpath, options) end
unique()
click to toggle source
# File lib/el_finder_ftp/pathname.rb, line 136 def unique return self.dup unless fullpath.file? copy = 1 begin new_file = self.class.new(@adapter, dirname + "#{basename_sans_extension} #{copy}#{extname}") copy += 1 end while new_file.exist? new_file end