mirror of
https://github.com/kemko/paperclip.git
synced 2026-01-01 16:05:40 +03:00
Fix rubocop lint warnings
This commit is contained in:
@@ -238,7 +238,7 @@ module Paperclip
|
||||
attachment_for(name).file?
|
||||
end
|
||||
|
||||
validates_each(name) do |record, attr, value|
|
||||
validates_each(name) do |record, _attr, _value|
|
||||
attachment = record.attachment_for(name)
|
||||
attachment.send(:flush_errors) unless attachment.valid?
|
||||
end
|
||||
@@ -307,21 +307,21 @@ module Paperclip
|
||||
end
|
||||
|
||||
def each_attachment
|
||||
self.class.attachment_definitions.each do |name, definition|
|
||||
self.class.attachment_definitions.each do |name, _definition|
|
||||
yield(name, attachment_for(name))
|
||||
end
|
||||
end
|
||||
|
||||
def save_attached_files
|
||||
logger.info("[paperclip] Saving attachments.")
|
||||
each_attachment do |name, attachment|
|
||||
each_attachment do |_name, attachment|
|
||||
attachment.send(:save)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_attached_files
|
||||
logger.info("[paperclip] Deleting attachments.")
|
||||
each_attachment do |name, attachment|
|
||||
each_attachment do |_name, attachment|
|
||||
attachment.send(:queue_existing_for_delete)
|
||||
attachment.send(:flush_deletes)
|
||||
end
|
||||
@@ -330,7 +330,7 @@ module Paperclip
|
||||
|
||||
def flush_attachment_jobs
|
||||
logger.info("[paperclip] flushing jobs.")
|
||||
each_attachment do |name, attachment|
|
||||
each_attachment do |_name, attachment|
|
||||
attachment.try(:flush_jobs)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -451,7 +451,7 @@ module Paperclip
|
||||
end
|
||||
|
||||
def flush_errors #:nodoc:
|
||||
errors.each do |error, message|
|
||||
errors.each do |_error, message|
|
||||
[message].flatten.each {|m| instance.errors.add(name, m) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,13 +21,13 @@ module Paperclip
|
||||
end
|
||||
|
||||
module Running
|
||||
def run_paperclip_callbacks(callback, opts = nil, &blk)
|
||||
def run_paperclip_callbacks(callback, _opts = nil, &blk)
|
||||
# The overall structure of this isn't ideal since after callbacks run even if
|
||||
# befores return false. But this is how rails 3's callbacks work, unfortunately.
|
||||
if run_callbacks(:"before_#{callback}"){ |result, object| result == false } != false
|
||||
if run_callbacks(:"before_#{callback}"){ |result, _object| result == false } != false
|
||||
blk.call
|
||||
end
|
||||
run_callbacks(:"after_#{callback}"){ |result, object| result == false }
|
||||
run_callbacks(:"after_#{callback}"){ |result, _object| result == false }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -39,7 +39,7 @@ module Paperclip
|
||||
if rails_version >= Gem::Version.new('5.0')
|
||||
{}
|
||||
elsif rails_version >= Gem::Version.new('4.1')
|
||||
{terminator: ->(target, result) { result == false }}
|
||||
{terminator: ->(_target, result) { result == false }}
|
||||
else
|
||||
{terminator: 'result == false'}
|
||||
end
|
||||
|
||||
@@ -36,7 +36,7 @@ module Paperclip
|
||||
|
||||
# Parses a "WxH" formatted string, where W is the width and H is the height.
|
||||
def self.parse string
|
||||
if match = (string && string.match(/\b(\d*)x?(\d*)\b(?:,(\d?))?([\>\<\#\@\%^!])?/i))
|
||||
if (match = (string && string.match(/\b(\d*)x?(\d*)\b(?:,(\d?))?([\>\<\#\@\%^!])?/i)))
|
||||
Geometry.new(
|
||||
width: match[1],
|
||||
height: match[2],
|
||||
@@ -129,9 +129,9 @@ module Paperclip
|
||||
|
||||
def cropping dst, ratio, scale
|
||||
if ratio.horizontal? || ratio.square?
|
||||
"%dx%d+%d+%d" % [ dst.width, dst.height, 0, (self.height * scale - dst.height) / 2 ]
|
||||
"%dx%d+%d+%d" % [ dst.width, dst.height, 0, ((self.height * scale) - dst.height) / 2 ]
|
||||
else
|
||||
"%dx%d+%d+%d" % [ dst.width, dst.height, (self.width * scale - dst.width) / 2, 0 ]
|
||||
"%dx%d+%d+%d" % [ dst.width, dst.height, ((self.width * scale) - dst.width) / 2, 0 ]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,29 +39,29 @@ module Paperclip
|
||||
end
|
||||
|
||||
# Returns the filename, the same way as ":basename.:extension" would.
|
||||
def filename attachment, style_name
|
||||
def filename(attachment, style_name)
|
||||
"#{basename(attachment, style_name)}.#{extension(attachment, style_name)}"
|
||||
end
|
||||
|
||||
# This interpolation is used in the default :path to ease default specifications.
|
||||
# So it just interpolates :url template without checking if preocessing and
|
||||
# file existence.
|
||||
def url attachment, style_name
|
||||
def url(attachment, style_name)
|
||||
interpolate(attachment.class.url_template, attachment, style_name)
|
||||
end
|
||||
|
||||
# Returns the timestamp as defined by the <attachment>_updated_at field
|
||||
def timestamp attachment, style_name
|
||||
def timestamp(attachment, _style_name)
|
||||
attachment.instance_read(:updated_at).to_s
|
||||
end
|
||||
|
||||
# Returns the Rails.root constant.
|
||||
def rails_root attachment, style_name
|
||||
def rails_root(_attachment, _style_name)
|
||||
Rails.root
|
||||
end
|
||||
|
||||
# Returns the Rails.env constant.
|
||||
def rails_env attachment, style_name
|
||||
def rails_env(_attachment, _style_name)
|
||||
Rails.env
|
||||
end
|
||||
|
||||
@@ -69,38 +69,38 @@ module Paperclip
|
||||
# e.g. "users" for the User class.
|
||||
# NOTE: The arguments need to be optional, because some tools fetch
|
||||
# all class names. Calling #class will return the expected class.
|
||||
def class attachment = nil, style_name = nil
|
||||
def class(attachment = nil, style_name = nil)
|
||||
return super() if attachment.nil? && style_name.nil?
|
||||
plural_cache.underscore_and_pluralize_class(attachment.instance.class)
|
||||
end
|
||||
|
||||
# Returns the basename of the file. e.g. "file" for "file.jpg"
|
||||
def basename attachment, style_name
|
||||
def basename(attachment, _style_name)
|
||||
File.basename(attachment.original_filename, ".*")
|
||||
end
|
||||
|
||||
# Returns the extension of the file. e.g. "jpg" for "file.jpg"
|
||||
# If the style has a format defined, it will return the format instead
|
||||
# of the actual extension.
|
||||
def extension attachment, style_name
|
||||
def extension(attachment, style_name)
|
||||
((style_name = attachment.styles[style_name]) && style_name[:format]) ||
|
||||
File.extname(attachment.original_filename)[1..-1] || ''
|
||||
end
|
||||
|
||||
# Returns the id of the instance.
|
||||
def id attachment, style_name
|
||||
def id(attachment, _style_name)
|
||||
attachment.instance.id
|
||||
end
|
||||
|
||||
# Returns the id of the instance in a split path form. e.g. returns
|
||||
# 000/001/234 for an id of 1234.
|
||||
def id_partition attachment, style_name
|
||||
def id_partition(attachment, _style_name)
|
||||
("%09d" % attachment.instance.id).scan(/\d{3}/).join("/")
|
||||
end
|
||||
|
||||
# Returns the pluralized form of the attachment name. e.g.
|
||||
# "avatars" for an attachment of :avatar
|
||||
def attachment attachment, style_name
|
||||
def attachment(attachment, _style_name)
|
||||
plural_cache.pluralize_symbol(attachment.name)
|
||||
end
|
||||
|
||||
|
||||
@@ -16,8 +16,7 @@ module IOStream
|
||||
def stream_to object, path_or_file, in_blocks_of = 8192
|
||||
dstio = case path_or_file
|
||||
when String then File.new(path_or_file, "wb+")
|
||||
when IO then path_or_file
|
||||
when Tempfile then path_or_file
|
||||
when IO, Tempfile then path_or_file
|
||||
end
|
||||
buffer = ""
|
||||
object.rewind
|
||||
|
||||
@@ -8,7 +8,7 @@ module Paperclip
|
||||
class ValidateAttachmentSizeMatcher
|
||||
def initialize attachment_name
|
||||
@attachment_name = attachment_name
|
||||
@low, @high = 0, (1.0/0)
|
||||
@low, @high = 0, Float::INFINITY
|
||||
end
|
||||
|
||||
def less_than size
|
||||
@@ -68,12 +68,12 @@ module Paperclip
|
||||
end
|
||||
|
||||
def lower_than_high?
|
||||
return true if @high == (1.0/0)
|
||||
return true if @high == Float::INFINITY
|
||||
passes_validation_with_size(@high - 1)
|
||||
end
|
||||
|
||||
def higher_than_high?
|
||||
return true if @high == (1.0/0)
|
||||
return true if @high == Float::INFINITY
|
||||
not passes_validation_with_size(@high + 1)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,7 +15,8 @@ module Paperclip
|
||||
Paperclip::Upfile.content_type_from_file(@file.path)
|
||||
end
|
||||
|
||||
def optimize(file)
|
||||
def optimize(_file)
|
||||
# TODO: use the arg?
|
||||
src = @file.path
|
||||
dst = "#{src}-#{SecureRandom.hex}"
|
||||
src_shell = src.shellescape
|
||||
|
||||
@@ -2,7 +2,7 @@ module Paperclip
|
||||
class Railtie < Rails::Railtie
|
||||
initializer 'paperclip.railtie.configure' do
|
||||
if defined? Rails.root
|
||||
Dir.glob(File.join(File.expand_path(Rails.root), "lib", "paperclip_processors", "*.rb")).each do |processor|
|
||||
Dir.glob(File.join(File.expand_path(Rails.root), "lib", "paperclip_processors", "*.rb")).sort.each do |processor|
|
||||
require processor
|
||||
end
|
||||
end
|
||||
|
||||
@@ -130,7 +130,7 @@ module Paperclip
|
||||
# Enqueues all pending jobs. First, jobs are placed to internal queue in flush_writes
|
||||
# (in after_save) and this method pushes them for execution (in after_commit).
|
||||
def flush_jobs
|
||||
queued_jobs&.each(&:call).clear
|
||||
queued_jobs&.each(&:call)&.clear
|
||||
end
|
||||
|
||||
def upload_to(store_id)
|
||||
|
||||
@@ -319,7 +319,8 @@ module Paperclip
|
||||
break if File.exist?(path) # Ruby 1.9.2 does not raise if the removal failed.
|
||||
end
|
||||
rescue Errno::EEXIST, Errno::EACCES, Errno::ENOTEMPTY,
|
||||
Errno::ENOENT, Errno::EINVAL, Errno::ENOTDIR, Errno::ESTALE => _e
|
||||
Errno::ENOENT, Errno::EINVAL, Errno::ENOTDIR, Errno::ESTALE
|
||||
# already deleted
|
||||
rescue SystemCallError => e
|
||||
Rollbar.error(e, {path: path, initial_path: initial_path})
|
||||
end
|
||||
@@ -333,7 +334,8 @@ module Paperclip
|
||||
-> { delete_local_files!(filenames) }
|
||||
end
|
||||
|
||||
def delete_local_files!(filenames = filesystem_paths.values)
|
||||
def delete_local_files!(_filenames = filesystem_paths.values)
|
||||
# TODO: _filenames как-то должно использоваться?
|
||||
filesystem_paths.values.each do |filename|
|
||||
log("Deleting local file #{filename}")
|
||||
delete_recursive(filename)
|
||||
@@ -341,7 +343,7 @@ module Paperclip
|
||||
end
|
||||
|
||||
def flush_jobs
|
||||
queued_jobs&.each(&:call).clear
|
||||
queued_jobs&.each(&:call)&.clear
|
||||
end
|
||||
|
||||
def upload_to(store_id)
|
||||
|
||||
@@ -52,7 +52,7 @@ module Paperclip
|
||||
begin
|
||||
log("deleting #{path}")
|
||||
FileUtils.rm(path)
|
||||
rescue Errno::ENOENT => e
|
||||
rescue Errno::ENOENT
|
||||
# ignore file-not-found, let everything else pass
|
||||
end
|
||||
begin
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace :paperclip do
|
||||
desc "Regenerates content_type/size metadata for a given CLASS (and optional ATTACHMENT)."
|
||||
task :metadata => :environment do
|
||||
for_all_attachments do |instance, name|
|
||||
if file = instance.send(name).to_file
|
||||
if (file = instance.send(name).to_file)
|
||||
instance.send("#{name}_file_name=", instance.send("#{name}_file_name").strip)
|
||||
instance.send("#{name}_content_type=", file.content_type.strip)
|
||||
instance.send("#{name}_file_size=", file.size) if instance.respond_to?("#{name}_file_size")
|
||||
|
||||
Reference in New Issue
Block a user