class Alchemy::Custom::Model::ElFinder::Paths::Base
Attributes
path[R]
root[R]
volume[R]
Public Class Methods
new(root, path = '.', opts = {})
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 8 def initialize(root, path = '.', opts = {}) Rails.logger.debug {root.inspect} Rails.logger.debug {path.inspect} @volume = opts.delete(:volume) @root = root.is_a?(PathName) ? root.root : ::Pathname.new(root) @path = ::Pathname.new(path) @path = path.is_a?(PathName) ? path.path : ::Pathname.new(path) if absolute? if @path.cleanpath.to_s.start_with?(@root.to_s) @path = ::Pathname.new @path.to_s.slice((@root.to_s.length + 1)..-1) elsif @path.cleanpath.to_s.start_with?(@root.realpath.to_s) @path = ::Pathname.new @path.to_s.slice((@root.realpath.to_s.length + 1)..-1) 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
absolute?()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 51 def absolute? @path.absolute? end
basename(*args)
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 93 def basename(*args) @path.basename(*args) end
basename_sans_extension()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 100 def basename_sans_extension @path.basename(@path.extname) end
child_directories(with_directory = true)
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 137 def child_directories(with_directory = true) realpath.children(with_directory).select {|child| child.directory?}.map {|e| self.class.new(@root, e, volume: @volume)} end
children(with_directory = true)
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 263 def children(with_directory = true) [] end
cleanpath()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 79 def cleanpath fullpath.cleanpath end
directory?()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 231 def directory? true end
dirname()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 115 def dirname self.class.new(@root, @path.dirname, volume: @volume) end
duplicate()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 170 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(@root, dirname + "#{_basename} copy #{copy}#{extname}", volume: @volume) copy += 1 end while new_file.exist? new_file end
extname()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 122 def extname @path.nil? ? '' : @path.extname end
file?()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 223 def file? false end
fisical_path()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 283 def fisical_path '' end
full_fill_paylod(payload)
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 291 def full_fill_paylod(payload) payload end
fullpath()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 72 def fullpath @path.nil? ? @root : @root + @path end
global_id()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 287 def global_id nil end
is_image?()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 227 def is_image? false end
is_root?()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 45 def is_root? Rails.logger.debug {"IS_ROOT?:#{@path} - #{ @path.to_s == '.'}"} @path.to_s == '.' end
mime_type()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 279 def mime_type 'directory' end
mtime()
click to toggle source
def basename
''
end
def parent_path
self.root
end
def path
File.join(self.root, basename)
end
## # Data Di modifica della cartella
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 258 def mtime DateTime.now end
name()
click to toggle source
Nome visualizzato in interfaccia
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 275 def name self.basename.to_s end
outside_of_root?()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 65 def outside_of_root? !cleanpath.to_s.start_with?(@root.to_s) end
realpath()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 86 def realpath fullpath end
relative?()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 58 def relative? @path.relative? end
relative_to(other)
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 152 def relative_to(other) @path.relative_path_from(other) end
rename(to)
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 187 def rename(to) to = self.class.new(@root, to.to_s, volume: @volume) realpath.rename(to.fullpath.to_s) rescue Errno::EXDEV FileUtils.move(realpath.to_s, to.fullpath.to_s) ensure @path = to.path end
tmb()
click to toggle source
url per la thumb
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 269 def tmb nil end
to_s()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 129 def to_s cleanpath.to_s end
Also aliased as: to_str
unique()
click to toggle source
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 157 def unique return self.dup unless self.file? copy = 1 begin new_file = self.class.new(@root, dirname + "#{basename_sans_extension} #{copy}#{extname}", volume: @volume) copy += 1 end while new_file.exist? new_file end
with_sub_dirs?()
click to toggle source
def is_root?
false
end
# File lib/alchemy/custom/model/el_finder/paths/base.rb, line 239 def with_sub_dirs? false end