Module Paperclip
In: lib/dm-paperclip/attachment.rb
lib/dm-paperclip/callback_compatability.rb
lib/dm-paperclip/geometry.rb
lib/dm-paperclip/interpolations.rb
lib/dm-paperclip/processor.rb
lib/dm-paperclip/storage.rb
lib/dm-paperclip/thumbnail.rb
lib/dm-paperclip/upfile.rb
lib/dm-paperclip/validations.rb
lib/dm-paperclip.rb

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

Methods

Classes and Modules

Module Paperclip::CallbackCompatability
Module Paperclip::ClassMethods
Module Paperclip::Interpolations
Module Paperclip::Resource
Module Paperclip::Storage
Module Paperclip::Upfile
Module Paperclip::Validate
Class Paperclip::Attachment
Class Paperclip::Configuration
Class Paperclip::Geometry
Class Paperclip::Processor
Class Paperclip::Tempfile
Class Paperclip::Thumbnail

Constants

VERSION = "2.4.1"

Public Class methods

[Source]

    # File lib/dm-paperclip.rb, line 67
67:   def self.config
68:     @config ||= Configuration.new
69:   end

[Source]

    # File lib/dm-paperclip.rb, line 63
63:   def self.config=(config)
64:     @config = config
65:   end

To configure Paperclip, put this code in an initializer, Rake task, or wherever:

  Paperclip.configure do |config|
    config.root               = Rails.root # the application root to anchor relative urls (defaults to Dir.pwd)
    config.env                = Rails.env  # server env support, defaults to ENV['RACK_ENV'] or 'development'
    config.use_dm_validations = true       # validate attachment sizes and such, defaults to false
    config.processors_path    = 'lib/pc'   # relative path to look for processors, defaults to 'lib/paperclip_processors'
  end

[Source]

    # File lib/dm-paperclip.rb, line 58
58:   def self.configure
59:     yield @config = Configuration.new
60:     Paperclip.config = @config
61:   end

[Source]

     # File lib/dm-paperclip.rb, line 134
134:     def interpolates key, &block
135:       Paperclip::Interpolations[key] = block
136:     end

Log a paperclip-specific line. Uses ActiveRecord::Base.logger by default. Set Paperclip.options[:log] to false to turn off.

[Source]

     # File lib/dm-paperclip.rb, line 184
184:     def log message
185:       logger.info("[paperclip] #{message}") if logging?
186:     end

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

  • whiny: Will raise an error if Paperclip cannot process thumbnails of an uploaded image. Defaults to true.
  • log: Logs progress to the Rails log. Uses ActiveRecord‘s logger, so honors log levels, etc. 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.

[Source]

     # File lib/dm-paperclip.rb, line 115
115:     def options
116:       @options ||= {
117:         :whiny             => true,
118:         :image_magick_path => nil,
119:         :command_path      => nil,
120:         :log               => true,
121:         :log_command       => false,
122:         :swallow_stderr    => true
123:       }
124:     end

[Source]

    # File lib/dm-paperclip.rb, line 71
71:   def self.require_processors
72:     return if @processors_already_required
73:     Dir.glob(File.expand_path("#{Paperclip.config.processors_path}/*.rb")).sort.each do |processor|
74:       require processor
75:     end
76:     @processors_already_required = true
77:   end

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.

This method can log the command being run when Paperclip.options[:log_command] is set to true (defaults to false). This will only log if logging in general is set to true as well.

[Source]

     # File lib/dm-paperclip.rb, line 151
151:     def run cmd, params = "", expected_outcodes = 0
152:       command = %Q<#{%Q[#{path_for_command(cmd)} #{params}].gsub(/\s+/, " ")}>
153:       command = "#{command} 2>#{bit_bucket}" if Paperclip.options[:swallow_stderr]
154:       Paperclip.log(command) if Paperclip.options[:log_command]
155:       output = `#{command}`
156:       unless [expected_outcodes].flatten.include?($?.exitstatus)
157:         raise PaperclipCommandLineError, "Error while running #{cmd}"
158:       end
159:       output
160:     end

[Validate]