Commit 04140e5a by Jon Yurek

Moved logging aroud, extracted column checks, changed column check to attr_accessor check.

parent 1ef75b0b
......@@ -116,6 +116,18 @@ module Paperclip
end
processor
end
def log message
logger.info("[paperclip] #{message}") if logging?
end
def logger
ActiveRecord::Base.logger
end
def logging?
options[:log]
end
end
class PaperclipError < StandardError #:nodoc:
......
......@@ -61,11 +61,7 @@ module Paperclip
# If the file that is assigned is not valid, the processing (i.e.
# thumbnailing, etc) will NOT be run.
def assign uploaded_file
%w(file_name).each do |field|
unless @instance.class.column_names.include?("#{name}_#{field}")
raise PaperclipError.new("#{@instance.class} model does not have required column '#{name}_#{field}'")
end
end
ensure_required_accessors!
if uploaded_file.is_a?(Paperclip::Attachment)
uploaded_file = uploaded_file.to_file(:original)
......@@ -254,16 +250,16 @@ module Paperclip
private
def logger #:nodoc:
instance.logger
def ensure_required_accessors!
%w(file_name).each do |field|
unless @instance.respond_to?("#{name}_#{field}") && @instance.respond_to?("#{name}_#{field}=")
raise PaperclipError.new("#{@instance.class} model missing required attr_accessor for '#{name}_#{field}'")
end
end
end
def log message #:nodoc:
logger.info("[paperclip] #{message}") if logging?
end
def logging? #:nodoc:
Paperclip.options[:log]
Paperclip.log(message)
end
def valid_assignment? file #:nodoc:
......
......@@ -39,7 +39,7 @@ module Paperclip
@queued_for_write.each do |style, file|
file.close
FileUtils.mkdir_p(File.dirname(path(style)))
logger.info("[paperclip] saving #{path(style)}")
log("saving #{path(style)}")
FileUtils.mv(file.path, path(style))
FileUtils.chmod(0644, path(style))
end
......@@ -49,7 +49,7 @@ module Paperclip
def flush_deletes #:nodoc:
@queued_for_delete.each do |path|
begin
logger.info("[paperclip] deleting #{path}")
log("deleting #{path}")
FileUtils.rm(path) if File.exist?(path)
rescue Errno::ENOENT => e
# ignore file-not-found, let everything else pass
......@@ -62,7 +62,7 @@ module Paperclip
rescue Errno::EEXIST, Errno::ENOTEMPTY, Errno::ENOENT, Errno::EINVAL, Errno::ENOTDIR
# Stop trying to remove parent directories
rescue SystemCallError => e
logger.info("[paperclip] There was an unexpected error while deleting directories: #{e.class}")
log("There was an unexpected error while deleting directories: #{e.class}")
# Ignore it
end
end
......@@ -194,7 +194,7 @@ module Paperclip
def flush_writes #:nodoc:
@queued_for_write.each do |style, file|
begin
logger.info("[paperclip] saving #{path(style)}")
log("saving #{path(style)}")
key = s3_bucket.key(path(style))
key.data = file
key.put(nil, @s3_permissions, {'Content-type' => instance_read(:content_type)}.merge(@s3_headers))
......@@ -208,7 +208,7 @@ module Paperclip
def flush_deletes #:nodoc:
@queued_for_delete.each do |path|
begin
logger.info("[paperclip] deleting #{path}")
log("deleting #{path}")
if file = s3_bucket.key(path)
file.delete
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment