The base module that gets included in ActiveRecord::Base. See the documentation for Paperclip::ClassMethods for more useful information.
# File lib/dm-paperclip.rb, line 74 def self.config @config ||= Configuration.new end
# File lib/dm-paperclip.rb, line 70 def self.config=(config) @config = config 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
# File lib/dm-paperclip.rb, line 65 def self.configure yield @config = Configuration.new Paperclip.config = @config end
# File lib/dm-paperclip.rb, line 185 def each_instance_with_attachment(klass, name) Object.const_get(klass).all.each do |instance| yield(instance) if instance.send(:"#{name}?") end end
# File lib/dm-paperclip.rb, line 141 def interpolates key, &block Paperclip::Interpolations[key] = block end
Log a paperclip-specific line. Uses ActiveRecord::Base.logger by default. Set Paperclip.options to false to turn off.
# File lib/dm-paperclip.rb, line 193 def log message logger.info("[paperclip] #{message}") if logging? 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.
# File lib/dm-paperclip.rb, line 122 def options @options ||= { :whiny => true, :image_magick_path => nil, :command_path => nil, :log => true, :log_command => true, :swallow_stderr => true } end
# File lib/dm-paperclip.rb, line 78 def self.require_processors return if @processors_already_required Dir.glob(File.expand_path("#{Paperclip.config.processors_path}/*.rb")).sort.each do |processor| require processor end @processors_already_required = true end
The run method takes a command to execute and an array 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. These codes should be passed as a hash as the last argument, like so:
Paperclip.run("echo", "something", :expected_outcodes => [0,1,2,3])
This method can log the command being run when Paperclip.options is set to true (defaults to false). This will only log if logging in general is set to true as well.
# File lib/dm-paperclip.rb, line 161 def run cmd, *params if options[:image_magick_path] Paperclip.log("[DEPRECATION] :image_magick_path is deprecated and will be removed. Use :command_path instead") end CommandLine.path = options[:command_path] || options[:image_magick_path] CommandLine.new(cmd, *params).run end
Generated with the Darkfish Rdoc Generator 2.