Class: Paperclip::AdapterRegistry
- Inherits:
-
Object
- Object
- Paperclip::AdapterRegistry
- Defined in:
- lib/paperclip/io_adapters/registry.rb
Defined Under Namespace
Classes: NoHandlerError
Instance Attribute Summary collapse
-
#registered_handlers ⇒ Object
readonly
Returns the value of attribute registered_handlers.
Instance Method Summary collapse
- #for(target) ⇒ Object
- #handler_for(target) ⇒ Object
-
#initialize ⇒ AdapterRegistry
constructor
A new instance of AdapterRegistry.
- #register(handler_class, &block) ⇒ Object
- #registered?(target) ⇒ Boolean
Constructor Details
#initialize ⇒ AdapterRegistry
Returns a new instance of AdapterRegistry.
7 8 9 |
# File 'lib/paperclip/io_adapters/registry.rb', line 7 def initialize @registered_handlers = [] end |
Instance Attribute Details
#registered_handlers ⇒ Object (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
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 |