Class: Paperclip::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/paperclip/processor.rb

Overview

Paperclip processors allow you to modify attached files when they are attached in any way you are able. Paperclip itself uses command-line programs for its included Thumbnail processor, but custom processors are not required to follow suit.

Processors are required to be defined inside the Paperclip module and are also required to be a subclass of Paperclip::Processor. There is only one method you must implement to properly be a subclass: #make, but #initialize may also be of use. #initialize accepts 3 arguments: the file that will be operated on (which is an instance of File), a hash of options that were defined in has_attached_file’s style hash, and the Paperclip::Attachment itself. These are set as instance variables that can be used within ‘#make`.

#make must return an instance of File (Tempfile is acceptable) which contains the results of the processing.

See Paperclip.run for more information about using command-line utilities from within Processors.

Direct Known Subclasses

Thumbnail

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}, attachment = nil) ⇒ Processor

Returns a new instance of Processor.



24
25
26
27
28
# File 'lib/paperclip/processor.rb', line 24

def initialize file, options = {}, attachment = nil
  @file = file
  @options = options
  @attachment = attachment
end

Instance Attribute Details

#attachmentObject

Returns the value of attribute attachment.



22
23
24
# File 'lib/paperclip/processor.rb', line 22

def attachment
  @attachment
end

#fileObject

Returns the value of attribute file.



22
23
24
# File 'lib/paperclip/processor.rb', line 22

def file
  @file
end

#optionsObject

Returns the value of attribute options.



22
23
24
# File 'lib/paperclip/processor.rb', line 22

def options
  @options
end

Class Method Details

.make(file, options = {}, attachment = nil) ⇒ Object



33
34
35
# File 'lib/paperclip/processor.rb', line 33

def self.make file, options = {}, attachment = nil
  new(file, options, attachment).make
end

Instance Method Details

#convert(arguments = "", local_options = {}) ⇒ Object

The convert method runs the convert binary with the provided arguments. See Paperclip.run for the available options.



39
40
41
42
43
44
45
# File 'lib/paperclip/processor.rb', line 39

def convert(arguments = "", local_options = {})
  Paperclip.run(
    Paperclip.options[:is_windows] ? "magick convert" : "convert",
    arguments,
    local_options,
  )
end

#identify(arguments = "", local_options = {}) ⇒ Object

The identify method runs the identify binary with the provided arguments. See Paperclip.run for the available options.



49
50
51
52
53
54
55
# File 'lib/paperclip/processor.rb', line 49

def identify(arguments = "", local_options = {})
  Paperclip.run(
    Paperclip.options[:is_windows] ? "magick identify" : "identify",
    arguments,
    local_options,
  )
end

#makeObject



30
31
# File 'lib/paperclip/processor.rb', line 30

def make
end