class RoadForest::ContentHandling::Engine::TypeHandlerList

Attributes

handlers[R]
type_map[R]
types[R]

Public Class Methods

new(prefix) click to toggle source
# File lib/roadforest/content-handling/engine.rb, line 10
def initialize(prefix)
  @prefix = prefix
  @types = MediaTypeList.new
  @handlers = {}
  @type_map = []
  @symbol_lookup = {}
end

Public Instance Methods

add(handler) click to toggle source
# File lib/roadforest/content-handling/engine.rb, line 19
def add(handler)
  type = handler.type
  @types.add(type)
  @handlers[type] = handler
  symbol = handler_symbol(type)
  raise "Type collision: #{type} already in #{self.inspect}" if @symbol_lookup.has_key?(symbol)
  @type_map << [type.content_type_header, symbol]
  @symbol_lookup[symbol] = handler
end
fetch(symbol, &block) click to toggle source
# File lib/roadforest/content-handling/engine.rb, line 33
def fetch(symbol, &block)
  @symbol_lookup.fetch(symbol, &block)
end
handler_for(type) click to toggle source
# File lib/roadforest/content-handling/engine.rb, line 41
def handler_for(type)
  type = MediaType.parse(type)
  @handlers.fetch(type)
rescue KeyError
  raise UnrecognizedType, "No Content-Type handler for #{type}"
end
handler_symbol(type) click to toggle source
# File lib/roadforest/content-handling/engine.rb, line 29
def handler_symbol(type)
  "#{@prefix}_#{type.accept_header.gsub(/\W/, "_")}".to_sym
end
reset() click to toggle source
# File lib/roadforest/content-handling/engine.rb, line 37
def reset
  @handlers.clear
end