diff options
author | Alyssa Ross <hi@alyssa.is> | 2016-11-23 23:31:38 +0000 |
---|---|---|
committer | Andrea Faulds <ajf@ajf.me> | 2016-11-24 00:30:58 +0000 |
commit | cefef2c57197a06d403b9cbe13e969e08aaf5301 (patch) | |
tree | a25d334dd3b5ea3c8281b1f71dd13c89064faaf9 /app/models | |
parent | 7161f91313b51c8425bd184dc5374084fd4e68a8 (diff) |
Extract filename obfuscation into module
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/concerns/obfuscate_filename.rb | 16 |
1 files changed, 16 insertions, 0 deletions
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 |