Class: Alchemy::Custom::Model::ElFinder::Paths::Base
- Inherits:
-
Object
- Object
- Alchemy::Custom::Model::ElFinder::Paths::Base
show all
- Defined in:
- lib/alchemy/custom/model/el_finder/paths/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(root, path = '.', opts = {}) ⇒ Base
Returns a new instance of Base.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# 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
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
5
6
7
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 5
def path
@path
end
|
#root ⇒ Object
Returns the value of attribute root.
5
6
7
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 5
def root
@root
end
|
#volume ⇒ Object
Returns the value of attribute volume.
5
6
7
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 5
def volume
@volume
end
|
Instance Method Details
#absolute? ⇒ Boolean
51
52
53
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 51
def absolute?
@path.absolute?
end
|
#basename(*args) ⇒ Object
93
94
95
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 93
def basename(*args)
@path.basename(*args)
end
|
#basename_sans_extension ⇒ Object
100
101
102
|
# 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) ⇒ Object
137
138
139
|
# 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) ⇒ Object
263
264
265
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 263
def children(with_directory = true)
[]
end
|
#cleanpath ⇒ Object
79
80
81
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 79
def cleanpath
fullpath.cleanpath
end
|
#directory? ⇒ Boolean
231
232
233
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 231
def directory?
true
end
|
#dirname ⇒ Object
115
116
117
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 115
def dirname
self.class.new(@root, @path.dirname, volume: @volume)
end
|
#duplicate ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# 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 ⇒ Object
122
123
124
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 122
def extname
@path.nil? ? '' : @path.extname
end
|
#file? ⇒ Boolean
223
224
225
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 223
def file?
false
end
|
#fisical_path ⇒ Object
283
284
285
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 283
def fisical_path
''
end
|
#full_fill_paylod(payload) ⇒ Object
291
292
293
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 291
def full_fill_paylod(payload)
payload
end
|
#fullpath ⇒ Object
72
73
74
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 72
def fullpath
@path.nil? ? @root : @root + @path
end
|
#global_id ⇒ Object
287
288
289
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 287
def global_id
nil
end
|
#is_image? ⇒ Boolean
227
228
229
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 227
def is_image?
false
end
|
#is_root? ⇒ Boolean
45
46
47
48
|
# 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 ⇒ Object
279
280
281
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 279
def mime_type
'directory'
end
|
#mtime ⇒ Object
def basename
''
end
def parent_path
self.root
end
def path
File.join(self.root, basename)
end
## # Data Di modifica della cartella
258
259
260
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 258
def mtime
DateTime.now
end
|
#name ⇒ Object
Nome visualizzato in interfaccia
275
276
277
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 275
def name
self.basename.to_s
end
|
#outside_of_root? ⇒ Boolean
65
66
67
|
# 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 ⇒ Object
86
87
88
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 86
def realpath
fullpath
end
|
#relative? ⇒ Boolean
58
59
60
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 58
def relative?
@path.relative?
end
|
#relative_to(other) ⇒ Object
152
153
154
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 152
def relative_to(other)
@path.relative_path_from(other)
end
|
#rename(to) ⇒ Object
187
188
189
190
191
192
193
194
|
# 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 ⇒ Object
269
270
271
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 269
def tmb
nil
end
|
#to_s ⇒ Object
Also known as:
to_str
129
130
131
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 129
def to_s
cleanpath.to_s
end
|
#unique ⇒ Object
157
158
159
160
161
162
163
164
165
|
# 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? ⇒ Boolean
239
240
241
|
# File 'lib/alchemy/custom/model/el_finder/paths/base.rb', line 239
def with_sub_dirs?
false
end
|