Parent

Sinatra::RespondWith::Format

Public Class Methods

new(app) click to toggle source
# File lib/sinatra/respond_with.rb, line 90
def initialize(app)
  @app, @map, @generic, @default = app, {}, {}, nil
end

Public Instance Methods

finish() click to toggle source
# File lib/sinatra/respond_with.rb, line 104
def finish
  yield self if block_given?
  mime_type = @app.content_type             ||
    @app.request.preferred_type(@map.keys)  ||
    @app.request.preferred_type             ||
    'text/html'
  type = mime_type.split(/\s*;\s*/, 2).first
  handlers = [@map[type], @generic[type[/^[^\/]+/]], @default].compact
  handlers.each do |block|
    if result = block.call(type)
      @app.content_type mime_type
      @app.halt result
    end
  end
  @app.halt 406
end
method_missing(method, *args, &block) click to toggle source
# File lib/sinatra/respond_with.rb, line 121
def method_missing(method, *args, &block)
  return super if args.any? or block.nil? or not @app.mime_type(method)
  on(method, &block)
end
on(type, &block) click to toggle source
# File lib/sinatra/respond_with.rb, line 94
def on(type, &block)
  @app.settings.mime_types(type).each do |mime|
    case mime
    when '*/*'            then @default     = block
    when /^([^\/]+)\/\*$/ then @generic[$1] = block
    else                       @map[mime]   = block
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.