Class: Paperclip::AdapterRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/paperclip/io_adapters/registry.rb

Defined Under Namespace

Classes: NoHandlerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAdapterRegistry



7
8
9
# File 'lib/paperclip/io_adapters/registry.rb', line 7

def initialize
  @registered_handlers = []
end

Instance Attribute Details

#registered_handlersObject (readonly)

Returns the value of attribute registered_handlers



5
6
7
# File 'lib/paperclip/io_adapters/registry.rb', line 5

def registered_handlers
  @registered_handlers
end

Instance Method Details

#for(target) ⇒ Object



28
29
30
# File 'lib/paperclip/io_adapters/registry.rb', line 28

def for(target)
  handler_for(target).new(target)
end

#handler_for(target) ⇒ Object

Raises:



15
16
17
18
19
20
# File 'lib/paperclip/io_adapters/registry.rb', line 15

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

#register(handler_class, &block) ⇒ Object



11
12
13
# File 'lib/paperclip/io_adapters/registry.rb', line 11

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

#registered?(target) ⇒ Boolean



22
23
24
25
26
# File 'lib/paperclip/io_adapters/registry.rb', line 22

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