Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 33 lines (26 sloc) 0.713 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
module Paperclip
  class AdapterRegistry
    class NoHandlerError < Paperclip::Error; end

    attr_reader :registered_handlers

    def initialize
      @registered_handlers = []
    end

    def register(handler_class, &block)
      @registered_handlers << [block, handler_class]
    end

    def handler_for(target)
      @registered_handlers.each do |tester, handler|
        return handler if tester.call(target)
      end
      raise NoHandlerError.new("No handler found for #{target.inspect}")
    end

    def registered?(target)
      @registered_handlers.any? do |tester, handler|
        handler === target
      end
    end

    def for(target)
      handler_for(target).new(target)
    end
  end
end
Something went wrong with that request. Please try again.