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