Module: Paperclip::ProcessorHelpers

Included in:
Paperclip
Defined in:
lib/paperclip/processor_helpers.rb

Defined Under Namespace

Classes: NoSuchProcessor

Instance Method Summary collapse

Instance Method Details

#clear_processors!Object



35
36
37
# File 'lib/paperclip/processor_helpers.rb', line 35

def clear_processors!
  @known_processors.try(:clear)
end

#load_processor(name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/paperclip/processor_helpers.rb', line 17

def load_processor(name)
  if defined?(Rails.root) && Rails.root
    filename = "#{name.to_s.underscore}.rb"
    directories = %w(lib/paperclip lib/paperclip_processors)

    required = directories.map do |directory|
      pathname = File.expand_path(Rails.root.join(directory, filename))
      file_exists = File.exist?(pathname)
      require pathname if file_exists
      file_exists
    end

    unless required.any?
      raise LoadError, "Could not find the '#{name}' processor in any of these paths: #{directories.join(', ')}"
    end
  end
end

#processor(name) ⇒ Object

:nodoc:



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/paperclip/processor_helpers.rb', line 5

def processor(name) #:nodoc:
  @known_processors ||= {}
  if @known_processors[name.to_s]
    @known_processors[name.to_s]
  else
    name = name.to_s.camelize
    load_processor(name) unless Paperclip.const_defined?(name)
    processor = Paperclip.const_get(name)
    @known_processors[name.to_s] = processor
  end
end

#register_processor(name, processor) ⇒ Object

You can add your own processor via the Paperclip configuration. Normally Paperclip will load all processors from the Rails.root/lib/paperclip_processors directory, but here you can add any existing class using this mechanism.

Paperclip.configure do |c|
  c.register_processor :watermarker, WatermarkingProcessor.new
end


47
48
49
50
# File 'lib/paperclip/processor_helpers.rb', line 47

def register_processor(name, processor)
  @known_processors ||= {}
  @known_processors[name.to_s] = processor
end