module Rack::App::Payload::Parser::Builder::Formats

Constants

FORM_CONTENT_TYPES

CSV_CONTENT_TYPE = [

"text/comma-separated-values",
"application/csv",
"text/csv",

]

CSV_PARSER = proc do |io|

CSV.parse(io.read)

end

def csv(builder)

require "csv"
CSV_CONTENT_TYPE.each do |content_type|
  builder.on(content_type, &CSV_PARSER)
end

rescue LoadError end

FORM_PARSER
FORM_SEP_CHAR
JSON_CONTENT_TYPES
JSON_PARSER
JSON_STREAM_CONTENT_TYPES
JSON_STREAM_PARSER
NULL_END_CHAR
RACK_QUERY_PARSER

Public Instance Methods

accept(builder, *form_names) click to toggle source
# File lib/rack/app/payload/parser/builder/formats.rb, line 99
def accept(builder, *form_names)
  last_name = nil
  form_names.map(&:to_sym).each do |form_name|
    last_name = form_name
    unless respond_to?(form_name)
      raise(NotImplementedError, "unknown formatter: #{last_name}")
    end
    __send__ form_name, builder
  end
end
form(builder)
Alias for: www_form_urlencoded
json(builder) click to toggle source
# File lib/rack/app/payload/parser/builder/formats.rb, line 23
def json(builder)
  require 'json'
  JSON_CONTENT_TYPES.each do |content_type|
    builder.on(content_type, &JSON_PARSER)
  end
end
json_stream(builder) click to toggle source
# File lib/rack/app/payload/parser/builder/formats.rb, line 40
def json_stream(builder)
  JSON_STREAM_CONTENT_TYPES.each do |content_type|
    builder.on(content_type, &JSON_STREAM_PARSER)
  end
end
urlencoded(builder)
Alias for: www_form_urlencoded
www_form_urlencoded(builder) click to toggle source
# File lib/rack/app/payload/parser/builder/formats.rb, line 90
def www_form_urlencoded(builder)
  FORM_CONTENT_TYPES.each do |content_type|
    builder.on(content_type, &FORM_PARSER)
  end
end
Also aliased as: form, urlencoded