Sha256: 1fb6e452c3683af0c3d1177c82747700e8467af07179b86eeedda823c2b8e26a

Contents?: true

Size: 1.59 KB

Versions: 31

Compression:

Stored size: 1.59 KB

Contents

module Paperclip
  module ProcessorHelpers
    class NoSuchProcessor < StandardError; end

    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

    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

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

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

    # 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
    def register_processor(name, processor)
      @known_processors ||= {}
      @known_processors[name.to_s] = processor
    end
  end
end

Version data entries

31 entries across 29 versions & 6 rubygems

Version Path
kt-paperclip-5.4.0 lib/paperclip/processor_helpers.rb
kt-paperclip-4.4.0 lib/paperclip/processor_helpers.rb
paperclip-6.1.0 lib/paperclip/processor_helpers.rb
paperclip-6.0.0 lib/paperclip/processor_helpers.rb
paperclip-5.3.0 lib/paperclip/processor_helpers.rb
paperclip-5.2.1 lib/paperclip/processor_helpers.rb
paperclip-5.2.0 lib/paperclip/processor_helpers.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/paperclip-5.1.0/lib/paperclip/processor_helpers.rb
paperclip-5.1.0 lib/paperclip/processor_helpers.rb
paperclip-5.0.0 lib/paperclip/processor_helpers.rb
paperclip-4.3.7 lib/paperclip/processor_helpers.rb
paperclip_jk-5.0.0.beta2 lib/paperclip/processor_helpers.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/paperclip-4.3.6/lib/paperclip/processor_helpers.rb
paperclip-5.0.0.beta2 lib/paperclip/processor_helpers.rb
paperclip-5.0.0.beta1 lib/paperclip/processor_helpers.rb
paperclip-4.3.6 lib/paperclip/processor_helpers.rb
paperclip-4.3.5 lib/paperclip/processor_helpers.rb
paperclip-4.3.4 lib/paperclip/processor_helpers.rb
paperclip-4.3.3 lib/paperclip/processor_helpers.rb
paperclip-4.3.2 lib/paperclip/processor_helpers.rb