Module: Wpxf::Helpers::Export
Overview
Provides helper methods for common functionality used to export files.
Instance Method Summary collapse
-
#export_and_log_loot(content, description, type, extension = '') ⇒ Models::LootItem
Save content to a new file and log the loot in the database.
-
#export_path ⇒ String
The path to save the file to.
-
#generate_unique_filename(file_extension) ⇒ String
The path to a unique filename in the wpxf home directory.
-
#register_export_path_option(required) ⇒ StringOption
Register the export_path option.
Methods included from Db::Loot
Instance Method Details
#export_and_log_loot(content, description, type, extension = '') ⇒ Models::LootItem
Save content to a new file and log the loot in the database.
41 42 43 44 45 |
# File 'lib/wpxf/helpers/export.rb', line 41 def export_and_log_loot(content, description, type, extension = '') filename = generate_unique_filename(extension) File.write(filename, content) store_loot filename, description, type end |
#export_path ⇒ String
Returns the path to save the file to.
24 25 26 27 |
# File 'lib/wpxf/helpers/export.rb', line 24 def export_path return nil if normalized_option_value('export_path').nil? File. normalized_option_value('export_path') end |
#generate_unique_filename(file_extension) ⇒ String
Returns the path to a unique filename in the wpxf home directory.
30 31 32 33 34 35 |
# File 'lib/wpxf/helpers/export.rb', line 30 def generate_unique_filename(file_extension) storage_path = File.join(Dir.home, '.wpxf', 'loot') FileUtils.mkdir_p(storage_path) unless File.directory?(storage_path) filename = "#{Time.now.strftime('%Y-%m-%d_%H-%M-%S')}#{file_extension}" File.join(storage_path, filename) end |
#register_export_path_option(required) ⇒ StringOption
Register the export_path option.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/wpxf/helpers/export.rb', line 12 def register_export_path_option(required) opt = StringOption.new( name: 'export_path', desc: 'The path to save the file to', required: required ) register_option(opt) opt end |