Module: Paperclip
- Defined in:
- lib/paperclip.rb,
lib/paperclip/style.rb,
lib/paperclip/upfile.rb,
lib/paperclip/railtie.rb,
lib/paperclip/version.rb,
lib/paperclip/geometry.rb,
lib/paperclip/matchers.rb,
lib/paperclip/processor.rb,
lib/paperclip/thumbnail.rb,
lib/paperclip/attachment.rb,
lib/paperclip/storage/s3.rb,
lib/paperclip/command_line.rb,
lib/paperclip/interpolations.rb,
lib/paperclip/storage/database.rb,
lib/paperclip/storage/filesystem.rb,
lib/paperclip/callback_compatability.rb,
lib/paperclip/matchers/have_attached_file_matcher.rb,
lib/paperclip/matchers/validate_attachment_size_matcher.rb,
lib/paperclip/matchers/validate_attachment_presence_matcher.rb,
lib/paperclip/matchers/validate_attachment_content_type_matcher.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, Glue, InstanceMethods, Interpolations, Shoulda, Storage, Upfile Classes: Attachment, CommandLine, CommandNotFoundError, Geometry, InfiniteInterpolationError, NotIdentifiedByImageMagickError, PaperclipCommandLineError, PaperclipError, Processor, Railtie, StorageMethodNotFound, Style, Tempfile, Thumbnail
Constant Summary collapse
- VERSION =
"2.3.6"
Class Method Summary collapse
- .configure {|_self| ... } ⇒ Object
- .interpolates(key, &block) ⇒ Object
-
.log(message) ⇒ Object
Log a paperclip-specific line.
-
.logger ⇒ Object
:nodoc:.
-
.logging? ⇒ Boolean
:nodoc:.
-
.options ⇒ Object
Provides configurability to Paperclip.
-
.processor(name) ⇒ Object
:nodoc:.
-
.run(cmd, *params) ⇒ Object
The run method takes a command to execute and an array of parameters that get passed to it.
Class Method Details
.configure {|_self| ... } ⇒ Object
75 76 77 |
# File 'lib/paperclip.rb', line 75 def configure yield(self) if block_given? end |
.interpolates(key, &block) ⇒ Object
79 80 81 |
# File 'lib/paperclip.rb', line 79 def interpolates key, &block Paperclip::Interpolations[key] = block end |
.log(message) ⇒ Object
Log a paperclip-specific line. Uses ActiveRecord::Base.logger by default. Set Paperclip.options to false to turn off.
118 119 120 |
# File 'lib/paperclip.rb', line 118 def log logger.info("[paperclip] #{}") if logging? end |
.logger ⇒ Object
:nodoc:
122 123 124 |
# File 'lib/paperclip.rb', line 122 def logger #:nodoc: ActiveRecord::Base.logger end |
.logging? ⇒ Boolean
:nodoc:
126 127 128 |
# File 'lib/paperclip.rb', line 126 def logging? #:nodoc: [:log] end |
.options ⇒ Object
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.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/paperclip.rb', line 64 def @options ||= { :whiny => true, :image_magick_path => nil, :command_path => nil, :log => true, :log_command => true, :swallow_stderr => true } end |
.processor(name) ⇒ Object
:nodoc:
107 108 109 110 111 112 113 114 |
# File 'lib/paperclip.rb', line 107 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) ⇒ Object
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.
99 100 101 102 103 104 105 |
# File 'lib/paperclip.rb', line 99 def run cmd, *params if [:image_magick_path] Paperclip.log("[DEPRECATION] :image_magick_path is deprecated and will be removed. Use :command_path instead") end CommandLine.path = [:command_path] || [:image_magick_path] CommandLine.new(cmd, *params).run end |