Module: Paperclip::ProcessorHelpers
- Included in:
- Paperclip
- Defined in:
- lib/paperclip/processor_helpers.rb
Defined Under Namespace
Classes: NoSuchProcessor
Instance Method Summary collapse
- #clear_processors! ⇒ Object
- #load_processor(name) ⇒ Object
-
#processor(name) ⇒ Object
:nodoc:.
-
#register_processor(name, processor) ⇒ Object
You can add your own processor via the Paperclip configuration.
Instance Method Details
#clear_processors! ⇒ Object
33 34 35 |
# File 'lib/paperclip/processor_helpers.rb', line 33 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 |
# 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.(Rails.root.join(directory, filename)) file_exists = File.exist?(pathname) require pathname if file_exists file_exists end raise LoadError, "Could not find the '#{name}' processor in any of these paths: #{directories.join(', ')}" unless required.any? 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
45 46 47 48 |
# File 'lib/paperclip/processor_helpers.rb', line 45 def register_processor(name, processor) @known_processors ||= {} @known_processors[name.to_s] = processor end |