Sha256: 7049c85d47b038a02ff6c9017b0998505c7556bbde536df23bb4ce65c10a2a65

Contents?: true

Size: 710 Bytes

Versions: 1

Compression:

Stored size: 710 Bytes

Contents

module Grape
  module Formatter
    class << self
      def builtin_formmaters
        {
          json: Grape::Formatter::Json,
          jsonapi: Grape::Formatter::Json,
          serializable_hash: Grape::Formatter::SerializableHash,
          txt: Grape::Formatter::Txt,
          xml: Grape::Formatter::Xml
        }
      end

      def formatters(options)
        builtin_formmaters.merge(options[:formatters] || {})
      end

      def formatter_for(api_format, options = {})
        spec = formatters(options)[api_format]
        case spec
        when nil
          ->(obj, _env) { obj }
        when Symbol
          method(spec)
        else
          spec
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-0.15.0 lib/grape/formatter.rb