From d836d9cc6944c19176769ecfa8bececb84cd08bf Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Sat, 19 Oct 2019 13:33:54 +0000 Subject: [PATCH] code cleanup: rubocop: fix Lint/IneffectiveAccessModifier in app/models/attachment.rb git-svn-id: http://svn.redmine.org/redmine/trunk@18781 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .rubocop_todo.yml | 1 - app/models/attachment.rb | 33 ++++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2fc81a28e..519f17fe2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -390,7 +390,6 @@ Lint/HandleExceptions: Lint/IneffectiveAccessModifier: Exclude: - - 'app/models/attachment.rb' - 'app/models/mail_handler.rb' Lint/InterpolationCheck: diff --git a/app/models/attachment.rb b/app/models/attachment.rb index e5adbb236..afba75e60 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -492,21 +492,24 @@ class Attachment < ActiveRecord::Base time.strftime("%Y/%m") end - # Returns an ASCII or hashed filename that do not - # exists yet in the given subdirectory - def self.disk_filename(filename, directory=nil) - timestamp = DateTime.now.strftime("%y%m%d%H%M%S") - ascii = '' - if %r{^[a-zA-Z0-9_\.\-]*$}.match?(filename) && filename.length <= 50 - ascii = filename - else - ascii = Digest::MD5.hexdigest(filename) - # keep the extension if any - ascii << $1 if filename =~ %r{(\.[a-zA-Z0-9]+)$} + # Singleton class method is public + class << self + # Returns an ASCII or hashed filename that do not + # exists yet in the given subdirectory + def disk_filename(filename, directory=nil) + timestamp = DateTime.now.strftime("%y%m%d%H%M%S") + ascii = '' + if %r{^[a-zA-Z0-9_\.\-]*$}.match?(filename) && filename.length <= 50 + ascii = filename + else + ascii = Digest::MD5.hexdigest(filename) + # keep the extension if any + ascii << $1 if filename =~ %r{(\.[a-zA-Z0-9]+)$} + end + while File.exist?(File.join(storage_path, directory.to_s, "#{timestamp}_#{ascii}")) + timestamp.succ! + end + "#{timestamp}_#{ascii}" end - while File.exist?(File.join(storage_path, directory.to_s, "#{timestamp}_#{ascii}")) - timestamp.succ! - end - "#{timestamp}_#{ascii}" end end