Sha256: e679b93c041e455c0c9bd38fa645a94f259ce06775e9c7702ce4f86ffca30935
Contents?: true
Size: 652 Bytes
Versions: 1
Compression:
Stored size: 652 Bytes
Contents
# frozen_string_literal: true module Grape module Formatter module_function DEFAULTS = { json: Grape::Formatter::Json, jsonapi: Grape::Formatter::Json, serializable_hash: Grape::Formatter::SerializableHash, txt: Grape::Formatter::Txt, xml: Grape::Formatter::Xml }.freeze DEFAULT_LAMBDA_FORMATTER = ->(obj, _env) { obj } def formatter_for(api_format, formatters) select_formatter(formatters, api_format) || DEFAULT_LAMBDA_FORMATTER end def select_formatter(formatters, api_format) formatters&.key?(api_format) ? formatters[api_format] : DEFAULTS[api_format] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
grape-2.2.0 | lib/grape/formatter.rb |