Class: ThemeStore::BaseImporter
- Inherits:
-
Object
- Object
- ThemeStore::BaseImporter
show all
- Defined in:
- lib/theme_store/base_importer.rb
Instance Method Summary
collapse
Instance Method Details
#[](value) ⇒ Object
9
10
11
12
13
|
# File 'lib/theme_store/base_importer.rb', line 9
def [](value)
fullpath = real_path(value)
return nil unless fullpath
File.read(fullpath)
end
|
#all_files ⇒ Object
35
36
37
|
# File 'lib/theme_store/base_importer.rb', line 35
def all_files
Dir.glob("**/**", base: temp_folder).reject { |f| File.directory?(File.join(temp_folder, f)) }
end
|
#cleanup! ⇒ Object
39
40
41
|
# File 'lib/theme_store/base_importer.rb', line 39
def cleanup!
FileUtils.rm_rf(temp_folder)
end
|
#file_size(path) ⇒ Object
29
30
31
32
33
|
# File 'lib/theme_store/base_importer.rb', line 29
def file_size(path)
fullpath = real_path(path)
return -1 unless fullpath
File.size(fullpath)
end
|
#import! ⇒ Object
5
6
7
|
# File 'lib/theme_store/base_importer.rb', line 5
def import!
raise "Not implemented"
end
|
#real_path(relative) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/theme_store/base_importer.rb', line 15
def real_path(relative)
fullpath = "#{temp_folder}/#{relative}"
return nil unless File.exist?(fullpath)
fullpath = Pathname.new(fullpath).realpath.to_s
if fullpath && fullpath.start_with?(temp_folder)
fullpath
else
nil
end
end
|
#temp_folder ⇒ Object
43
44
45
|
# File 'lib/theme_store/base_importer.rb', line 43
def temp_folder
@temp_folder ||= "#{Pathname.new(Dir.tmpdir).realpath}/discourse_theme_#{SecureRandom.hex}"
end
|