Class: ThemeStore::ZipExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/theme_store/zip_exporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(theme) ⇒ ZipExporter

Returns a new instance of ZipExporter.



9
10
11
12
13
14
# File 'lib/theme_store/zip_exporter.rb', line 9

def initialize(theme)
  @theme = theme
  @temp_folder = "#{Pathname.new(Dir.tmpdir).realpath}/discourse_theme_#{SecureRandom.hex}"
  @export_name = @theme.name.downcase.gsub(/[^0-9a-z.\-]/, "-")
  @export_name = "discourse-#{@export_name}" unless @export_name.starts_with?("discourse")
end

Instance Method Details

#cleanup!Object



24
25
26
# File 'lib/theme_store/zip_exporter.rb', line 24

def cleanup!
  FileUtils.rm_rf(@temp_folder)
end

#export_nameObject



16
17
18
# File 'lib/theme_store/zip_exporter.rb', line 16

def export_name
  @export_name
end

#package_filenameObject



20
21
22
# File 'lib/theme_store/zip_exporter.rb', line 20

def package_filename
  export_package
end

#with_export_dir(**kwargs) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/theme_store/zip_exporter.rb', line 28

def with_export_dir(**kwargs)
  export_to_folder(**kwargs)

  yield File.join(@temp_folder, @export_name)
ensure
  cleanup!
end