Sha256: a12ce43e230db70e3eb5f76d76fce61ea822ebb094577c60fa242bcf8c2e2a56
Contents?: true
Size: 852 Bytes
Versions: 6
Compression:
Stored size: 852 Bytes
Contents
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 unregister(handler_class) @registered_handlers.reject! { |_, klass| klass == 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, options = {}) handler_for(target).new(target, options) end end end
Version data entries
6 entries across 6 versions & 2 rubygems