Sha256: 84145f1726f562b518bd82045bcb7f4b4dad4432048bb6d8c5fe61fec3299bd8

Contents?: true

Size: 551 Bytes

Versions: 3

Compression:

Stored size: 551 Bytes

Contents

module Medie
  class Registry
    
    # adds a new handler to this registry
    def <<(what)
      use(what)
    end
    
    # adds a new handler to this registry
    def use(what)
      registry << what
      self
    end
    
    # Returns a handler that can handle this kind of media type.
    # It will always use the last registered handler.
    def for(media_type)
      registry.reverse.find do |handler|
        handler.can_handle?(media_type)
      end
    end
    
    private
    def registry
      @registry ||= []
    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
medie-1.0.0 lib/medie/registry.rb
medie-1.0.0.beta4 lib/medie/registry.rb
medie-1.0.0.beta3 lib/medie/registry.rb