Module: Paperclip

Defined in:
lib/paperclip.rb,
lib/paperclip/upfile.rb,
lib/paperclip/geometry.rb,
lib/paperclip/processor.rb,
lib/paperclip/thumbnail.rb,
lib/paperclip/attachment.rb,
lib/paperclip/callback_compatability.rb

Overview

The base module that gets included in ActiveRecord::Base. See the documentation for Paperclip::ClassMethods for more useful information.

Defined Under Namespace

Modules: CallbackCompatability, ClassMethods, InstanceMethods, Upfile Classes: Attachment, Geometry, NotIdentifiedByImageMagickError, PaperclipCommandLineError, PaperclipError, Processor, Tempfile, Thumbnail

Constant Summary collapse

VERSION =
"2.2.0"

Class Method Summary collapse

Class Method Details

.bit_bucketObject

:nodoc:



91
92
93
# File 'lib/paperclip.rb', line 91

def bit_bucket #:nodoc:
  File.exists?("/dev/null") ? "/dev/null" : "NUL"
end

.included(base) ⇒ Object

:nodoc:



95
96
97
98
99
100
# File 'lib/paperclip.rb', line 95

def included base #:nodoc:
  base.extend ClassMethods
  unless base.respond_to?(:define_callbacks)
    base.send(:include, Paperclip::CallbackCompatability)
  end
end

.optionsObject

Provides configurability to Paperclip. There are a number of options available, such as:

  • whiny_thumbnails: Will raise an error if Paperclip cannot process thumbnails of an uploaded image. Defaults to true.

  • command_path: Defines the path at which to find the command line programs if they are not visible to Rails the system’s search path. Defaults to nil, which uses the first executable found in the user’s search path.

  • image_magick_path: Deprecated alias of command_path.



56
57
58
59
60
61
62
# File 'lib/paperclip.rb', line 56

def options
  @options ||= {
    :whiny_thumbnails  => true,
    :image_magick_path => nil,
    :command_path      => nil
  }
end

.path_for_command(command) ⇒ Object

:nodoc:



64
65
66
67
68
69
70
71
72
# File 'lib/paperclip.rb', line 64

def path_for_command command #:nodoc:
  if options[:image_magick_path]
    ActiveSupport::Deprecation.warn(":image_magick_path is deprecated and "+
                                    "will be removed. Use :command_path "+
                                    "instead")
  end
  path = [options[:image_magick_path] || options[:command_path], command].compact
  File.join(*path)
end

.processor(name) ⇒ Object

:nodoc:



102
103
104
105
106
107
108
109
# File 'lib/paperclip.rb', line 102

def processor name #:nodoc:
  name = name.to_s.camelize
  processor = Paperclip.const_get(name)
  unless processor.ancestors.include?(Paperclip::Processor)
    raise PaperclipError.new("Processor #{name} was not found") 
  end
  processor
end

.run(cmd, params = "", expected_outcodes = 0) ⇒ Object

The run method takes a command to execute and a string of parameters that get passed to it. The command is prefixed with the :command_path option from Paperclip.options. If you have many commands to run and they are in different paths, the suggested course of action is to symlink them so they are all in the same directory.

If the command returns with a result code that is not one of the expected_outcodes, a PaperclipCommandLineError will be raised. Generally a code of 0 is expected, but a list of codes may be passed if necessary.



83
84
85
86
87
88
89
# File 'lib/paperclip.rb', line 83

def run cmd, params = "", expected_outcodes = 0
  output = `#{%Q[#{path_for_command(cmd)} #{params} 2>#{bit_bucket}].gsub(/\s+/, " ")}`
  unless [expected_outcodes].flatten.include?($?.exitstatus)
    raise PaperclipCommandLineError, "Error while running #{cmd}"
  end
  output
end