Browse Source

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
tags/4.1.0
Toshi MARUYAMA 4 years ago
parent
commit
d836d9cc69
2 changed files with 18 additions and 16 deletions
  1. 0
    1
      .rubocop_todo.yml
  2. 18
    15
      app/models/attachment.rb

+ 0
- 1
.rubocop_todo.yml View File

@@ -390,7 +390,6 @@ Lint/HandleExceptions:

Lint/IneffectiveAccessModifier:
Exclude:
- 'app/models/attachment.rb'
- 'app/models/mail_handler.rb'

Lint/InterpolationCheck:

+ 18
- 15
app/models/attachment.rb View File

@@ -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]+)$}
end
while File.exist?(File.join(storage_path, directory.to_s, "#{timestamp}_#{ascii}"))
timestamp.succ!
# 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
"#{timestamp}_#{ascii}"
end
end

Loading…
Cancel
Save