From cefef2c57197a06d403b9cbe13e969e08aaf5301 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Wed, 23 Nov 2016 23:31:38 +0000 Subject: Extract filename obfuscation into module --- app/models/concerns/obfuscate_filename.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/models/concerns/obfuscate_filename.rb (limited to 'app/models/concerns') diff --git a/app/models/concerns/obfuscate_filename.rb b/app/models/concerns/obfuscate_filename.rb new file mode 100644 index 000000000..dc25cdbc2 --- /dev/null +++ b/app/models/concerns/obfuscate_filename.rb @@ -0,0 +1,16 @@ +module ObfuscateFilename + extend ActiveSupport::Concern + + class_methods do + def obfuscate_filename(*args) + before_action { obfuscate_filename(*args) } + end + end + + def obfuscate_filename(path) + file = params.dig(*path) + return if file.nil? + + file.original_filename = "media" + File.extname(file.original_filename) + end +end -- cgit